Here’s the output of parseInt with different arguments: parseInt({foo:0},10));//NaN parseInt(10.7,10);////10 parseInt("10.7",10);////10 parseInt("7",10);//7
So, we should probably do something like: var val:Number = parseInt(value,10); return isNaN(val) ? 0 : val; What about uint? Something like this? var val:Number = parseInt(value,10); return isNaN(val) ? 0 : Math.abs(val); On May 17, 2016, at 6:13 PM, Alex Harui <aha...@adobe.com> wrote: > It seems like we should continue to have the compiler call Language._int() > and fix the implementation. Right now _int() just does this: > > static public function _int(value:Number):Number > { > return value >> 0; > } > > Which I think is an attempt to truncate the Number. Does JS parseInt > handle non-Strings? Otherwise _int() would probably need some typeof > tests to determine whether to truncate or call parseint. > > -Alex > > > > On 5/17/16, 7:53 AM, "Josh Tynjala" <joshtynj...@gmail.com> wrote: > >> If you use 10 as the radix, you're fine. The strange behavior is when you >> omit the radix because some browsers try to be smart and detect things >> like >> a leading 0 as an octal number. >> >> - Josh >> >> On Tue, May 17, 2016 at 12:17 AM, Tom Chiverton <t...@extravision.com> >> wrote: >> >>> I think parseInt() in JS has really odd behaviour and is best avoided. >>> >>> Tom >>> >>> On 17 May 2016 07:46:07 BST, Alex Harui <aha...@adobe.com> wrote: >>>> I pushed changes for just the "x as int" case. >>>> >>>> On 5/16/16, 12:30 PM, "Harbs" <harbs.li...@gmail.com> wrote: >>>> >>>>> I assume int() will cross-compile to parseInt()? >>>> >>>> Currently the compiler calls Language._int(), but the code in there >>>> doesn't call parseInt. Should it? >>>> >>>> -Alex >>>> >>>> >>>> ______________________________________________________________________ >>>> This email has been scanned by the Symantec Email Security.cloud >>>> service. >>>> For more information please visit http://www.symanteccloud.com >>>> ______________________________________________________________________ >>> >>> -- >>> Tom Chiverton >>> Sent from my phone. Please excuse my brevity. >