The result of this method is a String primitive representation of the numeric value, of the receiving object, rendered according to the passed-in radix value.
A radix is the number of discrete values in the counting sequence before a carry over digit is generated. Thus, the radix of decimal numbers is 10. With this mechanism, you can generate values to any radix. The radix is also called the base of the number system.
The radix value is in the range 2 to 36 and allows the numeric value to be reproduced in a variety of number bases.
A missing radix is assumed to be base 10.
Octal numbers use a radix value of 8.
Hexadecimal numbers use a radix value of 16.
Binary numbers use a radix value of 2.
For an example, refer to the Decimal value topic where this is used to generate a lookup table.
Before the radix conversion was available, this method simply converted to a string, which most commentators considered was unnecessary since JavaScript did this naturally without any need to add special scripting support. However, now that we can convert numeric values from one base to another, this function becomes far more useful.
Prev | Home | Next |
Number.toSource() | Up | Number.valueOf() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |