In JavaScript value type conversion, the most common conversion is between string and number values.
You can convert it into a string by calling the 4 functions of the number value (in fact, it is the 4 functions of the Number class after JS automatically converts the number value into a Number object):
1.toString().
2.toFixed().
3.toExponential().
4.toPrecision().
toString()
The toString() method can be called on the number value to convert it into a string. The toString() function accepts a positive integer between 2 and 36 as a parameter, which is used to define the base number of the value; if the parameter is missing, the toString() function will represent the corresponding value in decimal.
var b = 0xff;
console.log(b.toString());//255
toFixed()
The toFixed() function accepts an integer as a parameter, which specifies the exact number of digits after the decimal point. The parameter accepted by the toFixed() function can also be a negative number (although it is rarely used). When the parameter is a negative number, the integer part of the value will lose precision. When using the toFixed() function to adjust values, JavaScript follows the rounding principle.
toExponential()
You can use the toExponential() function to convert a value to scientific notation. The toExponential() function accepts a non-negative integer as a parameter (if this parameter is a negative number, a RangeError is thrown) as the precision of scientific notation. Like the toFixed() function, the toExponential() function follows the rounding principle when adjusting values.
toPrecision()
The toPrecision() function accepts a positive integer as a parameter (if the parameter is 0 or a negative number, the program will throw a RangeError), and takes it as the precise number of digits of the value (including the integer part and the decimal part). If the If the exact number of digits is less than the number of integer parts of the value, the value will be converted to scientific notation. Like the toFixed() function, the toPrecision() function follows the rounding principle when adjusting values.