JavaScript parseint ()

Source: Internet
Author: User

JavaScript parseint ()

Js parseint () function

 

During work, set the MTU value in the gateway and see this function. Usage:

 

Function saveMtu ()
{
Var maxMtu;
With (document. forms [0])
{
MaxMtu = parseInt (mtu. value );


If (isNaN (mtu. value ))
{
Alert (MTU value! + Mtu. value + invalid, value range (68--1500 )!);
Return 0;
}


If (maxMtu <68 || maxMtu> 1500)
{
Alert (MTU value! + Mtu. value + invalid, value range (68--1500 )!);
Return 0;
}
Loc + = & maxMtu = + maxMtu;
}
Return 1;
}

 

View W3C. It is interpreted as: A string can be parsed and an integer is returned.

 

parseInt(string, radix)
String is a required string to be parsed.

 

Radix is optional. The base number of the resolution. Similar to, the base number is parsed in decimal and hexadecimal notation. If this parameter is smaller than 2 or greater than 36, parseInt () returns NaN.

 

 

ParseInt (10); // returns 10 parseInt (19,10); // returns 19 (10 + 9) (decimal) parseInt (11,2); // returns 3 (2 + 1) (in hexadecimal notation, the left 1 is 2, and the right 1 is 1, so it is 2 + 1) parseInt (17,8); // returns 15 (8 + 7) (octal, 17 is equal to 8 for the left 1 and 7 for the right, so 8 + 7)
ParseInt (2f, 16); // return 47 (hexadecimal, 2*16 + 15 = 47) parseInt (010); // Undetermined: return 10 or 8

 

 

For example:

 


Print:

10
29
7
23
47
10
NaN

Related Article

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.