common-stuff
    Preparing search index...

    Function toInt

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

      Floats are truncated toward zero. Trailing non-numeric characters (e.g. '42abc') cause it to return undefined. Whitespace is trimmed.

      Parameters

      • value: string | number

      Returns undefined | number

      toInt('42')      // 42
      toInt(' -7 ') // -7
      toInt('1.9') // 1
      toInt('42abc') // undefined
      toInt('abc') // undefined
      toInt('') // undefined
      toInt(3.7) // 3