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

How to remove decimal part in javascript

青灯夜游
Release: 2021-11-24 15:40:17
Original
14252 people have browsed it

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

2. Use the ceil() function to round up

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

3. Use the floor() function to round down

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

4. Use the round() function to round

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

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

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