Home Web Front-end JS Tutorial Summary of using javaScript parseInt character to number function_Basic knowledge

Summary of using javaScript parseInt character to number function_Basic knowledge

May 16, 2016 pm 06:42 PM
javascript parseint number

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. ! ! ! ! ! ! ! ! ! !

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to implement an online reservation system using WebSocket and JavaScript

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

How to use JavaScript and WebSocket to implement a real-time online ordering system

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

Simple JavaScript Tutorial: How to Get HTTP Status Code

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

How to get HTTP status code in JavaScript the easy way

What are the platforms for virtual currency trading around the world? The top ten latest 2025 digital currency app rankings What are the platforms for virtual currency trading around the world? The top ten latest 2025 digital currency app rankings Feb 27, 2025 pm 06:09 PM

What are the platforms for virtual currency trading around the world? The top ten latest 2025 digital currency app rankings

See all articles