Summary of converting javaScript parseInt characters into numeric Functions

Source: Internet
Author: User

The problem was found during the test today. When the month in the database is 09, the problem occurs. After converting it with parseInt, it will become 0. I am puzzled. After a long test, I did not find any problems in my code. I searched google to find out that was the case.

For parseInt ("01") to parseInt ("07"); parseInt ("10") to later, you can get the correct result, but if it is parseInt ("08 ") or parseInt ("09"), the return value is 0. First, check the parseInt Syntax: parseInt (string, radix ); if the following parameters are not written, start with the first one and judge that string is the string to be converted. radix is binary, octal, hexadecimal or decimal. When radix is not specified by default, it is in hexadecimal format when 0x is switched. If 0 is switched and the second digit is not x, it is in octal format, (the error 0 is returned because there cannot be 8 or 9 in octal ). If it starts with 1, it will be in decimal format, so it will be right after 10. Therefore, we should specify the carry-in system in order to avoid errors. If we usually use decimal digits, we will use parseInt ("08", 10 );
Therefore, it is wrong. It is best to add a number after the parseInt function for future use to ensure no errors. Otherwise, the error occurred several hours .!!!!!!!!!!

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.