In javascript, regardless of Single-precision float and double-precision, all decimal variables are regarded as float. Therefore, to obtain the n digits after decimal places, use the toFixed (n) method to obtain
Convert js numbers to float and take N decimal places:
========================================================== =
All variables in javascript are weak types, and all variables are declared as var, which is not as convenient as java during the type conversion process. It uses parseInt, parseFloat (variable) type conversion. Note: There is no parseDouble (variable) type conversion, because in javascript, float and double are not single-precision. All decimal variables are considered float, therefore, you must use the toFixed (n) method to obtain the n digits after the decimal number.
For example:
Var f = 2.56556;
F. toFixed (2 );
The two digits after the decimal point of the variable f can be obtained through this method. If it is not a float type, type conversion (parseFloat) is also required.