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

How to convert float to int type in javascript

青灯夜游
Release: 2021-10-25 17:12:58
Original
8872 people have browsed it

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)
Copy after login

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

Math.ceil(7/2)
Copy after login

3. Round off

Math.round(7/2)
Copy after login

4 , Round down

Math.floor(7/2)
Copy after login

[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!

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