Home  >  Article  >  Web Front-end  >  How to convert float to int type in javascript

How to convert float to int type in javascript

青灯夜游
青灯夜游Original
2021-10-25 17:12:588773browse

Conversion method: 1. Use the "parseInt(float value)" statement; 2. Use the "Math.ceil(float value)" statement; 3. Use the "Math.round(float value)" statement; 4 , use the "Math.floor(float value)" statement.

How to convert float to int type in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript Force conversion of float to int type

1. Discard the decimal part and keep the integer part

parseInt(7/2)

2. Round up. If there is a decimal, add 1 to the integer part

Math.ceil(7/2)

3. Round off

Math.round(7/2)

4 , Round down

Math.floor(7/2)

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to convert float to int type in javascript. 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