JavaScript string to Number

Source: Internet
Author: User
Tags string to number

//The way to convert STR to digital, think of a long time ago a face test, say the way the character to the number, and now think aboutvarStr1= ' 4.88 ', str2= ' 4.8xx '; Console.log (parseint (str1))//4Console.log (str1|0)//4Console.log (str1-0)//4.88Console.log (+STR1)//4.88Console.log (-(-STR1))//4.88Console.log (~~STR1)//4Console.log (str1<<0)//4Console.log (str1>>0)//4Console.log (number (STR1))//4.88Console.log (parseint (str2))//4Console.log (str2|0)//0Console.log (str2-0)//NaNConsole.log (+STR2)//NaNConsole.log (-(-STR2))//NaNConsole.log (~~STR2)//0Console.log (str2<<0)//0Console.log (str2>>0)//0Console.log (number (STR2))//NaN//The str2 conversion may fail, the number, Pasreint, and the value are Nan, and the bitwise operation Gets the 0;-0 And number will get its true type, integer or floating-point type. And all the other direct get is the integral type//but I usually use xxx|0 XXX-0 .

JavaScript string to Number

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.