Home  >  Article  >  Web Front-end  >  How to remove decimal part in javascript

How to remove decimal part in javascript

青灯夜游
青灯夜游Original
2021-11-24 15:40:0914258browse

Removal method: 1. Use parseInt(), the syntax "parseInt(value)"; 2. Use ceil(), the syntax "Math.ceil(value)"; 3. Use floor(), the syntax " Math.floor(value)"; 4. Use round(), the syntax is "Math.round(value)".

How to remove decimal part in javascript

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

Javascript method to remove decimal part

1. Use parseInt() function to round

// 丢弃小数部分,保留整数部分
parseInt(3.141592654) // 3

2. Use the ceil() function to round up

// 向上取整,有小数就整数部分加1
Math.ceil(3.141592654) // 4

3. Use the floor() function to round down

// 向下取整,丢弃小数部分
Math.floor(3.141592654) // 3

4. Use the round() function to round

// 四舍五入
Math.round(3.141592654) // 3

[Related recommendations: javascript learning tutorial]

The above is the detailed content of How to remove decimal part 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