JavaScript provides three explicit type conversion functions: eval (), parseInt (), and parseFloat (). Js parsefloat parseint
JavaScript provides three explicit type conversion functions: eval (), parseInt (), and parseFloat ().
Eval () function: converts a string expression to a numeric value. For example, the result of the statement total = eval ("432.1*10") is total = 4321, which is about to assign the value 4321 to the total variable.
ParseInt () function: converts a string to an integer. The return value starts with the first character of the string. If the character does not start with an integer, 0 is returned. The parseInt () function can also convert hexadecimal or decimal numbers.
For example, parseInt ("123xyz") returns 123, while parseInt ("xyz") returns 0.
ParseFloat () function: similar to the parseInt () function, it returns the first floating point number contained in the string. If the string does not start with a valid floating point number, 0 is returned.
For example, parseFloat ("2.1e4xyz") returns 21000, while parseFloat ("xyz") returns 0.
In JavaScript, The parseFloat function method returns the floating point number obtained by String Conversion. Usage:
ParseFloat (numString) where the numString parameter is a string containing a floating point number. In JavaScript, The parseFloat function method returns the number representation equal to the number saved in numString. If the numString prefix cannot be interpreted as a floating point number, NaN (not a number) is returned ).
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.