SHARE
TWEET

string_to_real()

a guest Apr 18th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @param string
  2.  
  3. var _string = argument0;
  4.  
  5. var _fail_value = 0;
  6. var _hit_space  = false;
  7. var _hit_number = false;
  8.  
  9. var _size = string_length(_string);
  10. for(var _i = _size; _i > 0; _i--)
  11. {
  12.     var _character = string_char_at(_string, _i);
  13.     switch(_character)
  14.     {
  15.         case "0":
  16.         case "1":
  17.         case "2":
  18.         case "3":
  19.         case "4":
  20.         case "5":
  21.         case "6":
  22.         case "7":
  23.         case "8":
  24.         case "9":
  25.         case ".":
  26.         case "-":
  27.             if (_hit_space && _hit_number) return _fail_value;
  28.             _hit_space  = false;
  29.             _hit_number = true;
  30.         break;
  31.        
  32.         case " ":
  33.             _string = string_delete(_string, _i, 1);
  34.             _hit_space = true;
  35.         break;
  36.        
  37.         default:
  38.             return _fail_value;
  39.         break;
  40.     }
  41. }
  42.  
  43. if (string_count("-", _string) > 1) return undefined;
  44. if (string_count(".", _string) > 1) return undefined;
  45.  
  46. var _negative_pos = string_pos("-", _string);
  47. if (_negative_pos > 1) return undefined;
  48. if (string_pos(".", _string) == (1+_negative_pos)) return undefined;
  49.  
  50. return real(_string);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top