Javascript function parseint () bug problem _javascript technique

Source: Internet
Author: User
It's a very weird thing to test out today. parseint (1.13*100), the actual return value is 112. Just look at the code.
Copy Code code as follows:

<script type= "Text/javascript" >
function Test () {
var thisvalue = 0;
Thisvalue=yuantofen ($ ("#inp"). Val ());

alert (Thisvalue);
}
/* Meta-* *
function Yuantofen (yuan) {
return parseint (yuan*100,10);//Workaround: Change this here to: parseint (yuan*1000,10)/10;
}
</script>
<body>
<div>
<input type= "text" id= "INP" name= "pl" value= "1.14"/><!--when the input values are: 1.13, 1.14, 1.15, 1.16, this bug appears. No other data is currently found to have this bug-->
<input type= "button" Name= "OK" value= "confirms" onclick= "test ();" />
</div>
</body>

When you execute the above code, you will find that when you enter a number for the period of 1.13-1.16, such as entering a 1.13, but the value of alert is 1.12, the same, the input is 1.16 alert out of 1.15.

But that doesn't happen when you enter 2.13, 3.13, 0.13.

This bug is especially important for the most business accounts.

For example: you want to send money to So-and-so, remittance unit is (billion), your remittance 113 million, the result actually became 112 million. Ha ha. A joke. But the program is fastidious rigorous, no matter is a penny or 0.01 cents is who's who, must not be sloppy.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.