com/quirks [en]

All languages

Differences between version #9428 and #9429

30c30
< 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.
---
> The original parseInt for js targets treats inputs that start with 0 as octal by default.  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.  In order to prevent this behavior in standard javascript, it is necessary to specify a base as a second argument of the parseInt function (e.g. parseInt("09", 10)).  However, the Haxe version of this function does not provide a second argument, so this solution isn't appropriate in Haxe code.  All other Haxe targets use native parseInt implementations that parse "09" as 9.
32c32
< Suggested workarounds include stripping leading zeroes from strings in javascript for conversions:  
---
> Suggested workarounds include stripping leading zeroes from strings in javascript for conversions in order to provide a uniformly behaving method:  
43c43,45
< </code>
\ No newline at end of file
---
> </code>
> 
> 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]]
\ No newline at end of file

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

Previous | Next