com/quirks

Differences between version #9426 and #9427

30c30,43
< Std.parseInt treats inputs that start with 0 as octal.  Accordingly, Std.parseInt("09") will return 0 in many browsers.  This is appropriate according to a given ecmascript specification, but is a common source of errors for numeric parsing.  For an overview of the situation, see [[http://www.w3schools.com/jsref/jsref_parseInt.asp|the parseInt documentation]] and [[http://stackoverflow.com/questions/2547836/why-doesnt-an-octal-literal-as-a-string-cast-to-a-number|this stackoverflow response]] All other Haxe targets use native parseInt implementations that parse "09" as 9.
\ No newline at end of file
---
> Std.parseInt treats inputs that start with 0 as octal.  Accordingly, Std.parseInt("09") will return 0 in many browsers.  This is appropriate according to a given ecmascript specification, but is a common source of errors for numeric parsing.  For an overview of the situation, see [[http://www.w3schools.com/jsref/jsref_parseInt.asp|the parseInt documentation]] and [[http://stackoverflow.com/questions/2547836/why-doesnt-an-octal-literal-as-a-string-cast-to-a-number|this stackoverflow response]] All other Haxe targets use native parseInt implementations that parse "09" as 9.
> 
> Suggested workarounds include stripping leading zeroes from strings in javascript for conversions:  
> 
> <code haxe>
> 	public static function parseInt(str:String):Int{
> 		#if js
> 			str =	~/^0*(\d)/.replace(str, '$1');
> 			untyped return __js__('parseInt')(str);
> 		#else
> 			return Std.parseInt(str);
> 		#end
> 	}
> </code>
\ No newline at end of file

	
Ver Date Lg User Action
#11927 2011-11-30 12:19:29 en JLM Restored to version #11689
#11865 2011-11-30 11:37:28 en Anonymous View | Diff
#11689 2011-10-31 01:26:23 en njuneau View | Diff
#9524 2010-12-29 20:16:15 en jjdonald View | Diff
#9523 2010-12-29 20:15:22 en jjdonald View | Diff
#9522 2010-12-29 20:14:11 en jjdonald View | Diff
#9521 2010-12-29 20:13:41 en jjdonald View | Diff
#9434 2010-12-07 01:33:14 en jjdonald View | Diff
#9433 2010-12-07 01:31:08 en jjdonald View | Diff
#9432 2010-12-07 01:30:45 en jjdonald View | Diff
#9431 2010-12-07 01:30:35 en jjdonald View | Diff
#9430 2010-12-07 01:30:19 en jjdonald View | Diff
#9429 2010-12-07 01:29:52 en jjdonald View | Diff
#9428 2010-12-06 17:11:12 en jjdonald View | Diff
#9427 2010-12-06 17:09:41 en jjdonald View | Diff
#9426 2010-12-06 16:45:12 en jjdonald View | Diff
#9425 2010-12-06 16:42:40 en jjdonald View | Diff
#9424 2010-12-06 16:42:20 en jjdonald View | Diff
#9133 2010-08-23 17:24:42 en ianxm View | Diff
#8850 2010-06-29 22:46:24 en jjdonald View | Diff

Previous | Next