JS Built-ins
NumberparseFloatbeginner

Number.parseFloat() β€” leading/trailing whitespace ignored

πŸ“– Usage Example
// Parse a string to a floating-point number
Number.parseFloat('3.14')      // β†’ 3.14
Number.parseFloat('3.14abc')   // β†’ 3.14 (stops at first non-numeric)
Number.parseFloat('abc')       // β†’ NaN

Use Number.parseFloat() to convert a string to a decimal number, stopping at the first character that is not part of a valid number.

Number.parseFloat() β€” Whitespace

Leading and trailing whitespace is ignored.

Number.parseFloat('  2.5  ')  // β†’ 2.5
πŸ’‘ Hints (1)
  • β€’ Leading whitespace is stripped before parsing.