A so-called bug about the parseint function in JavaScript

Source: Internet
Author: User
javascript| function

Recently I was upgrading a calendar control, there are some inexplicable errors, and finally found that the original is a parseint function of a so-called bug caused by the parseint ("08") and parseint ("09") to return when processing is incredibly 0, and There is no such thing as a parsefloat function, and I have changed all the places I used to the parseint function to the parsefloat function.

Finally after the test found that the original when there are 0 of the time, parseint default to it as octal processing, 01--07 natural no problem, but 09,08 are unqualified octal form, so was treated in accordance with 0. To solve this problem, you can take advantage of another parameter of the parseint function, which is shown to tell parseint to be processed in decimal. For example we can do this parseint ("08", 10) or parseint ("09", 10). This will not be a problem. So the so-called bug should not be called as a bug, but we do not know much about it, ignoring an important parameter, just appeared this let us headache situation.



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.