Options
All
  • Public
  • Public/Protected
  • All
Menu

Common operations and tools related with numbers

Hierarchy

  • NumericUtils

Index

Methods

Static forceNumeric

  • forceNumeric(value: any, valueName?: string, errorMessage?: string): void
  • Strictly check that the provided value is numeric or throw an exception

    throws

    Error If the check fails

    Parameters

    • value: any

      A value to check

    • Default value valueName: string = ""

      The name of the value to be shown at the beginning of the exception message

    • Default value errorMessage: string = "must be numeric"

      The rest of the exception message

    Returns void

    void

Static forcePositiveInteger

  • forcePositiveInteger(value: any, valueName?: string, errorMessage?: string): void
  • Strictly check that the provided value is a positive integer or throw an exception

    throws

    Error If the check fails

    Parameters

    • value: any

      A value to check

    • Default value valueName: string = ""

      The name of the value to be shown at the beginning of the exception message

    • Default value errorMessage: string = "must be a positive integer"

      The rest of the exception message

    Returns void

    void

Static generateRandomInteger

  • generateRandomInteger(min: number, max: number): number
  • Generate a random integer between the specified range (both extremes are included).

    throws

    Exception if max is equal or less than min.

    Parameters

    • min: number

      lowest possible value (negative values are allowed)

    • max: number

      highest possible value (negative values are allowed)

    Returns number

    A random integer value between min and max

Static getNumeric

  • getNumeric(value: any): number
  • Get the number represented by the given value

    Parameters

    • value: any

      A value to convert to a number

    Returns number

    number The numeric type representation from the given value. For example, a string '0001' will return 1

Static isInteger

  • isInteger(value: any): boolean
  • Tells if the given value is a numeric integer or not

    Parameters

    • value: any

      A value to check

    Returns boolean

    true if the given value is a numeric integer or represents a a numeric integer value, false otherwise

Static isNumeric

  • isNumeric(value: any): boolean
  • Tells if the given value is numeric or not

    Parameters

    • value: any

      A value to check

    Returns boolean

    true if the given value is numeric or represents a numeric value, false otherwise

Generated using TypeDoc