Home > Web Front-end > JS Tutorial > body text

Summary of using javaScript parseInt character to number function_Basic knowledge

WBOY
Release: 2016-05-16 18:42:16
Original
1102 people have browsed it

I found a problem during the test today. When the month in the database is 09, there is a problem. After using parseInt to convert it, it becomes 0. So puzzled. After testing for a long time, no problem was found in my code. I searched it on Google and found out what it was.

For parseInt("01") to parseInt("07");parseInt("10"), the correct result can be obtained, but if it is parseInt("08") or parseInt("09 ") returns 0; First, look at the parseInt syntax: parseInt(string, radix); If the following parameters are not written, use the beginning of the first one to determine where string is the string to be converted, and radix is ​​binary, octal, or hexadecimal. or decimal. When radix is ​​not specified by default, when it is switched with 0x, it is hexadecimal; if it is switched with 0 and the second digit is not x, it is octal (because octal cannot have 8 or 9, so an error is reported and 0 is returned) . If it starts with 1, it is in decimal, so after 10, it is correct again. Therefore, we should clearly specify the carry system when we use it to prevent errors. If we usually use decimal digits, we use parseInt("08", 10);
So, it is wrong. When using it in the future, it is best to add the decimal number after the parseInt function to ensure that there is no error. Otherwise, there will be a delay of several hours. ! ! ! ! ! ! ! ! ! !

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template