'Does .toString(16) always return lowercase?
When converting a decimal number to a base above 10 using .toString(base), it seems that I always get a lower case string. Can I rely on this? An upper case string would be correct, although would need converting for my application.
Extra credit for referencing the part of the spec that defines this (I looked and couldn't find it) and for any counter-examples (browsers that return uppercase).
Example:
(12648430).toString(16) // returns: "c0ffee". Not "C0FFEE"
Solution 1:[1]
(12648430).toString(16) will always return: "c0ffee". Not "C0FFEE", after checking it with somes browsers, I found a confirmation:
The Number object overrides the toString() method of the Object object; it does not
inherit Object.prototype.toString(). For Number objects, the toString() method returns a string representation of the object in the specified radix.The toString() method parses its first argument, and attempts to return a string
representation in the specified radix (base). For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), a through f are used.
"for hexadecimal numbers (base 16), a through f are used".
See reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
