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 ).
Parsefloat ("ABC") // return Nan.
Parsefloat ("1.2abc") // return 1.2.