Parseint () and Nan ()

Source: Internet
Author: User

The parseint () function parses a string and returns an integer.
The parseint () method is used to convert a string to an integer.

Parseint (string, Radix): String required. All converted strings.
Radix option, 2 to 36, specifies the hexadecimal type of the string.

Code
< Script Type = " Text/JavaScript " >
Document. Write (parseint ( " 10 " )); // 10
Document. Write (parseint ( " 10.00 " )); // 10
Document. Write (parseint ( " 10.33 " )); // 10
Document. Write (parseint ( " 34 45 66 " )); // 34
Document. Write (parseint ( " 60 " )); // 60
Document. Write (parseint ( " 40 years " )); // 40
Document. Write (parseint ( " He was 40 " )); // Nan
Document. Write (parseint ( " 10 " )); // 10
Document. Write (parseint ( " 10 " , 10 )); // 10
Document. Write (parseint ( " 010 " )); // 8
Document. Write (parseint ( " 10 " , 8 )); // 8
Document. Write (parseint ( " 0x10 " )); // 16
Document. Write (parseint ( " 10 " , 16 )); // 16
< / SCRIPT>

After reading the above, you will certainly not understand Nan. Let's talk about Nan below.
Nan "not a number", this value is rare, so that we do not understand it. When the operation fails to return the correct value, the Nan value is returned. The Nan value is very special, because it is "not a number", so any number is not equal to it, or even Nan itself is not equal to Nan.

isnan calculates a parameter and checks whether it is a numerical value.
isnan (testvalue) returns true or false.
isnan is a built-in JavaScript function. It is not a method associated with any object, but a part of the language. On a platform that supports Nan, The parsefloat () and parseint () functions return "Nan" when calculating a value that is not a numerical value ". If the parameter passed by isnan () is "Nan", true is returned; otherwise, false is returned.

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.