parseint () function problem in JavaScript

Source: Internet
Author: User
javascript| Function | problem

This question may be overlooked, and I have encountered it in the project. Write a reminder to everyone!!!

When using JavaScript's parseint function, parseint ("08") or parseint ("09") returns incredibly 0, while parseint ("a") ... parseint ("07") are all right, it's hard to understand at first, The reason for this problem is that when there is a "0" in front of it, JavaScript's debugger think it is a octal number, and "08" and "09" are not a legitimate octal number, which leads to that problem, but parsefloat does not.

In fact, the parseint method has an optional parameter to represent the number, so this should not be a bug, but we don't usually notice the details. The solution is simply to use parseint ("08", 10) or parseint ("09", 10) to notify the JavaScript interpreter to use decimal to parse it.



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.