JS string conversion to digital summary

Source: Internet
Author: User

A. A lack of skills to convert a string to a number but it is clear that the numbers () constructor is called as a function:

var number = number (string_value);

B. parseint () intercepts only integers, if a string begins with "0x" or "0X", parseint () resolves it to a hexadecimal number, parseint () can even accept a parameter to specify the cardinality of the number to parse, with a valid value between 2 and 36

parseint ("3 Blind Mice"); Returns 3
parseint ("12.34"); Returns 12
parseint ("0xFF"); Returns 255
parseint ("11", 2); Returns 3 (1 * 2 + 1)
parseint ("FF", 16); Returns 255 (15 * 16 + 15)
parseint ("ZZ", 36); Returns 1295 (35 * 36 + 35)
parseint ("077", 8); Returns 63 (7 * 8 + 7)
parseint ("077", 10); Returns 77 (7 * 10 + 7)

C. parsefloat () intercepts integers and floating-point numbers.

Parsefloat ("3.14 meters"); Returns 3.14

D. If parseint () and parsefloat () are not able to convert the specified string to a number, they return Nan:

parseint (' eleven '); Returns Nan
Parsefloat ("$72.47"); Returns NaN

How JavaScript is rounded

A. Discard the fractional part, preserving the integral portion of the
parseint (5/2)

B. Rounding up, with decimals on the integer part plus 1

Math.ceil (5/2)

C. Rounding down

Math.floor (5/2)

D. Rounding

Math.Round (5/2)

JS string conversion to digital summary

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.