Other types of transfer number

Source: Internet
Author: User

Sub-implicit type conversions and explicit type conversions1. Implicit type conversion

+   -    *    /    %

1.1, + more Special:

if there is a string on eitherside of the +, then the+ connection function

+ If both sides are numbers, then the function of the addition operation

1.2,-*/%

when it comes to-*/%, the other types are converted to number types before the corresponding mathematical operations are performed.

2. Explicit type conversions

Number (), parseint (), parsefloat ()

2.1. Number ()

Number () to convert any value to a value

Common conversion instances

    varNUM1 = Number (true); varnum2 =Number (undefined); varnum3 = Number (NULL); varNUM4 = number ("Hello"); varNUM5 = Number (""); varNUM6 = number (123); Console.log (NUM1); //returns 1Console.log (NUM2);//return nanConsole.log (NUM3);//returns 0Console.log (NUM4);//return nanConsole.log (NUM5);//returns 0Console.log (NUM6);//back to 123

2.2, parseint ()

Convert a string to an integer

Common conversion instances

    varNUM1 = parseint ("12.34abc"); varnum2 = parseint ("abc1234"); varnum3 = parseint (""); varNUM4 = parseint ("100"); varNUM5 = parseint ("0xA"); Console.log (NUM1); //back toConsole.log (NUM2);//return nanConsole.log (NUM3);//return nanConsole.log (NUM4);//returnConsole.log (NUM5);//return ten
2.3, parsefloat ()
    varNUM1 = parsefloat ("12.34abc"); varnum2 = parsefloat ("abc1234"); varnum3 = parsefloat (""); varNUM4 = parsefloat ("100"); varNUM5 = parsefloat ("0xA"); Console.log (NUM1); //back to 12.34Console.log (NUM2);//return nanConsole.log (NUM3);//return nanConsole.log (NUM4);//returnConsole.log (NUM5);//returns 0

Parsefloat can only parse ten decimal

Other types of transfer 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.