Home >Web Front-end >JS Tutorial >Convert js numbers to float method sharing
Variables in JavaScript are all weak types. All variables are declared as var. The type conversion process is not as convenient as Java. It performs type conversion through parseInt (variable), parseFloat (variable) and other methods. . Note: There is no type conversion like parseDouble (variable), because there is no distinction between single-precision float and double-precision double in JavaScript. All variables with decimals are considered floats. Therefore, to get n digits after the decimal, use the method toFixed( n) to get.
For example:
var f=2.56556;
f.toFixed(2);
You can get the 2 decimal places of variable f, if it is not a float type, Type conversion (parseFloat(variable name)) is also required to obtain it through this method.
Related recommendations:
Several ways to clear float in CSS
How to deal with line breaks caused by the float attribute in html5
Summary on the correct usage of float and text wrapping issues
The above is the detailed content of Convert js numbers to float method sharing. For more information, please follow other related articles on the PHP Chinese website!