common-stuff
    Preparing search index...

    Function toFloat

    • Parses a value into a finite number, returning undefined if parsing fails.

      Unlike parseFloat, this is strict: trailing non-numeric characters (e.g. '1.5abc') cause it to return undefined. Whitespace is trimmed.

      Parameters

      • value: string | number

      Returns undefined | number

      toFloat('1.5')      // 1.5
      toFloat(' -3.2 ') // -3.2
      toFloat('1.5abc') // undefined
      toFloat('abc') // undefined
      toFloat('') // undefined
      toFloat(NaN) // undefined
      toFloat(2) // 2