Home  >  Article  >  Web Front-end  >  How to remove numbers after decimal point in javascript

How to remove numbers after decimal point in javascript

青灯夜游
青灯夜游Original
2021-06-17 16:22:0411721browse

The parseInt() function can be used in javascript to remove numbers after the decimal point. The syntax format is "parseInt (floating point number)". The parseInt() function will skip any number of leading spaces when parsing, parse as many numeric characters as possible, and return NaN if the first non-space character is a non-numeric character.

How to remove numbers after decimal point in javascript

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

javascript removes the numbers after the decimal point

<script type="text/javascript">

var num=3234.14;
var num2=parseInt(num);
console.log(num2);

</script>

Output:

How to remove numbers after decimal point in javascript

Related function description:

The parseInt() function parses a string and returns an integer.

The parseInt() function is a global function, does not belong to any class method, and only parses integers. If the string prefix is ​​"0x" or "0X", parseInt() interprets it as a hexadecimal number. It skips any number of leading spaces, parses as many numeric characters as possible, ignores what follows, and returns NaN if the first non-space character is a non-numeric character.

For example:

How to remove numbers after decimal point in javascript

[Related recommendations: javascript learning tutorial]

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