Thomas Fuchs recommends using double tilda (~~) for string conversion.
Safer and just as fast (
http://mir.aculo.us/2010/05/12/adventures-in-javascript-number-parsing/).

-L

On Tuesday, February 21, 2012, Murvin Lai wrote:

> proper use of parseInt is do that. parseInt(number, 10)  for 10-base.
>
> On Tue, Feb 21, 2012 at 2:16 PM, Andrew Chilton 
> <[email protected]<javascript:_e({}, 'cvml', '[email protected]');>
> > wrote:
>
>> On 22 February 2012 10:46, Tim Caswell 
>> <[email protected]<javascript:_e({}, 'cvml', '[email protected]');>>
>> wrote:
>> > While it's annoying, it's a good idea to always specify the radix (the
>> > second argument to parseInt) when parsing numbers and you know the
>> > radix. This is why jslint yells at you if you leave this "optional"
>> argument
>> > off.
>>
>> On a slightly different note, another good way (which Crockford also
>> suggests) is instead of using parseInt(), coerce the string into
>> number by using +'08'. This will give you the number 8.
>>
>> Note that in your case this may not be what you want since it gives a
>> number, not an integer. This is fine if you know your string contains
>> a round number, but not if your string can contain a decimal point.
>> e.g. +'08.5' will give you the number 8.5.
>>
>> If you ever use this in a calculation of some sort, it's also good to
>> put parens around your coerce. For example:
>>
>>    var x = something + (+'08') + whatever;
>>
>> Cheers,
>> Andy
>>
>> --
>> Andrew Chilton
>> e: [email protected] <javascript:_e({}, 'cvml',
>> '[email protected]');>
>> w: http://www.appsattic.com/
>>
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to 
>> [email protected]<javascript:_e({}, 'cvml', 
>> '[email protected]');>
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:_e({}, 'cvml',
>> 'nodejs%[email protected]');>
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>
>  --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to 
> [email protected]<javascript:_e({}, 'cvml', '[email protected]');>
> To unsubscribe from this group, send email to
> [email protected] <javascript:_e({}, 'cvml',
> 'nodejs%[email protected]');>
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>


-- 
Sent from Gmail Mobile

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to