Data type Review PARSEING&PARSEFLOAT--JS study notes 2015-6-2 (46th day)

Source: Internet
Author: User

Success lies in persistence, giving yourself this sentence;

Today, we review the numerical conversion methods of the two data types: parseint and parsefloat.

Compared to number () method, the two methods of parse are relatively diligent, from left to right, and number is a comprehensive analysis;

Can understand so parseint, he compared local tyrants, in the conversion value, from left to right, encountered non-digital time to stop the conversion, the back of the data are all thrown away;

But parseint is still relatively clever, when the value is preceded by a space, one or more 0 of the time, or will be successfully converted to an integer value, var num1 = parseint (' 0000200 ')//200

And parsefloat, the comparison "thrifty" encountered the decimal point (the first decimal point) or can continue to parse the future

Using both of these methods, we can determine whether a numeric value is not an integer:

var num = 109.88;

if (parseint (num) = = parsefloat (num)) {

Alert (num+ ' is an integer ');

}else{

Alert (num+ ' is decimal ')

}

Data type Review PARSEING&PARSEFLOAT--JS study notes 2015-6-2 (46th day)

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.