Home > Web Front-end > JS Tutorial > body text

Convert js numbers to float method sharing

小云云
Release: 2018-03-07 15:07:59
Original
4161 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!