JS parsefloat parseint Conversion Function _ basic knowledge

Source: Internet
Author: User
Tags numeric value
JS parsefloat parseint

JavaScript provides 3 explicit type conversion functions, namely, eval (), parseint (), and parsefloat ().

Eval () Function: Converts a string expression to a numeric value. For example, the result of a statement total=eval ("432.1*10") is that total=4321 assigns a value of 4321 to the total variable.

parseint () Function: Converts a string to an integer. Returns the start of the first character of the string and returns 0 if the character does not begin with an integer. The parseint () function can also convert hexadecimal or decimal digits.

For example: parseint ("123xyz") returns 123, and parseint ("xyz") returns 0.

Parsefloat () function: Similar to the parseint () function, which returns the first floating-point number contained on a string. Returns 0 if the string does not start with a valid floating-point number.

For example: parsefloat ("2.1e4xyz") returns 21000, while parsefloat ("xyz") returns 0.

The Parsefloat function method in JavaScript is to return a floating-point number converted from a string. How to use:

Parsefloat (numstring) where the numstring parameter is a string containing a floating-point number. The Parsefloat function method in JavaScript returns a numeric representation that is equal to the number saved in the numstring. Returns NaN (not a number) if the numstring prefix cannot be interpreted as a float.

Parsefloat ("abc")//Return NaN.
Parsefloat ("1.2ABC")//Return 1.2.

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.