Home  >  Article  >  Web Front-end  >  Convert js numbers to float method sharing

Convert js numbers to float method sharing

小云云
小云云Original
2018-03-07 15:07:594201browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn