jquery converts a string to a number

Source: Internet
Author: User

1:parseint (String)

parseint ("1234blue"); Returns 1234

parseint ("123"); Returns 123

parseint ("22.5"); Returns 22

parseint ("Blue"); Returns NaN

In addition, the parseint () method has a base mode, which is the ability to convert binary, octal, hexadecimal, or any other binary string into integers. The base is specified by the second parameter of the parseint () method, as in the following example:

parseint ("AF", 16); Returns 175

parseint ("10", 2); Returns 2

parseint ("10", 8); Returns 8

parseint ("10", 10); Returns 10

If the decimal number contains a leading 0, it is best to use cardinality 10 so that the octal value is not unexpectedly obtained. For example:

parseint ("010"); Returns 8

parseint ("010", 8); Returns 8

parseint ("010", 10); Returns 10

2:parsefloat (): parsefloat () No base mode

Parsefloat ("1234blue"); Returns 1234.0

Parsefloat ("0xA"); Returns NaN

Parsefloat ("22.5"); Returns 22.5

Parsefloat ("22.34.5"); Returns 22.34

Parsefloat ("0908"); Returns 908

Parsefloat ("Blue"); Returns NaN

3: Number():

Number (false) 0

Number (TRUE) 1

Number (undefined) NaN

Number (NULL) 0

Number ("5.5") 5.5

Number ("56") 56

Number ("5.6.7") NaN

Number (new Object ()) NaN

Number (100) 100

Reference: http://www.angelweb.cn/Html/jquery/jqueryjiaocheng/2867.html

jquery converts a string to a number

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.