The parseFloat()
function looks at each character starting in position 0.
It continues to parse the string until it reaches either the end of the string or a character that is invalid in a floating-point number.
A decimal point is valid the first time it appears, but a second decimal point is invalid.
For example, "22.34.5" is converted to 22.34.
parseFloat()
ignores the initial zeros.
Hexadecimal numbers always become 0.
Because parseFloat()
parses only decimal values, there is no radix mode.
If the string represents a whole number with no decimal point or only a zero after the decimal point, parseFloat()
returns an integer.
let num1 = parseFloat("1234asdf"); // 1234 - integer let num2 = parseFloat("0xA"); // 0 let num3 = parseFloat("2.5"); // 2.5 let num4 = parseFloat("2.34.5"); // 2.34 let num5 = parseFloat("0108.5"); // 108.5 let num6 = parseFloat("3.125e7"); // 31250000