Javascript - convert numbers to strings
How to convert a float or interger value to string using javascript?
The simplest way to convert any variable to a string is to add an empty string to that variable, for example:
a = a+'' // This converts a to string
b += '' // This converts b to string
Or you can use toString() function.
var a = 6.23;
a.toString();
This will return the string “6.23″.
The resultant string will hold the decimal representation of the original number.
For converting numbers to binary, octal, or hexadecimal strings (or to any other base) you can use, in JavaScript 1.1, the standard method Number.toString(radix) for converting a number to a string representing that number in a non-decimal number system (e.g. to a string of binary, octal or hexadecimal digits). For example:
a = (50274).toString(16) // this gives "c462"
b = (76).toString(8) // this gives "114"
c = (7623).toString(36) // this gives "5vr"
d = (100).toString(2) // this gives "1100100"
Popularity: 50% [?]




