Home > Web Front-end > JS Tutorial > The difference between parseInt and parseFloat in javascript_javascript skills

The difference between parseInt and parseFloat in javascript_javascript skills

WBOY
Release: 2016-05-16 17:29:00
Original
1613 people have browsed it

Look at the code first:

Copy the code The code is as follows:

<script> <br>alert(parseInt("3.54 apples")); <br>alert(parseFloat("3.54 apples")); <br></script>
<script><br>alert(parseInt(" 3.54 apples"));<br>alert(parseFloat("3.54 apples"));<br></script>

Running result:
The difference between parseInt and parseFloat in javascript_javascript skillsThe difference between parseInt and parseFloat in javascript_javascript skills

Both methods parseInt() and parseFloat() start searching from the string on the left, if the first character is not a number or a negative sign (it can also be a decimal point in parseFloat()). Once they encounter such a character, they return the number they extracted

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