Julian Turner said the following on 12/19/2006 6:07 AM:
> Randy Webb wrote:
>
> Hi
>
> May I hazard some amateur comments:-
>
> [snip]
>> <proposal>
>> The parseInt function decides what base to convert a string
>> to by looking at the string.
>
> Perhaps "...to convert a number represented in a string by...."
Changed.
>> It assumes that any string beginning
>> with '0x' or '0X' represents a hexadecimal Number,
>
> Should "Number" be in upper case? Might that confuse numeric literals,
> with JavaScript's internal Number data type?
Changed to lower case. Not sure why I made it Number instead of number.
> Perhaps "...indicates a number represented in hexadecimal..."
>> but it has a
>
> "...but, if an 'x' or 'X' is not present, has a..."
>> choice with a leading zero: the string can represent a Number that
>> can be either octal or decimal.
>
> "...could represent a number...."
Changed "can" to "could".
>> Assuming octal, the string '09'
>
> "A leading '0' will cause octal will be the first assumption, otherwise
> decimal is assumed. As a result the string '09'...."
I think that goes without saying.
>> will be converted to 0 (octal digits are 0-7);
>
> "....(valid octal digits are 0-7, so parseInt will stop parsing when it
> reaches '9')..."
I don't even think the (octal..) should be there.
>> assuming decimal, '09' will be converted to 9 (the leading zero is ignored). To force
>> use of a particular base, add a second parameter: parseInt("09",base).
>> </proposal>
>
> "To force use of a particular base, add a second parameter:
> parseInt("09",base). If decimal is forced, '09' will be converted to 9
> (the leading zero is ignored)."
Wouldn't that be obvious without saying it?
<new proposal>
The parseInt function decides what base to
convert a number represented as a string
to by looking at the string. It assumes that
any string beginning with '0x' or '0X' represents
a hexadecimal number, but it has a choice with a
leading zero: the string could represent a number
that can be either octal or decimal. Assuming
octal, the string '09' will be converted to 0
(octal digits are 0-7); assuming decimal, '09'
will be converted to 9 (the leading zero is
ignored). To force use of a particular base,
add a second parameter: parseInt("09",base).
</new proposal>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/