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

The difference between parseInt and parseFloat in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:29:001590browse

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

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