Options
All
  • Public
  • Public/Protected
  • All
Menu

Common operations and tools related with numbers

Hierarchy

  • NumericUtils

Index

Properties

Static Readonly NON_NUMERIC_ERROR

NON_NUMERIC_ERROR: "value is not numeric" = "value is not numeric"

Defines the error message for an exception when a non-numeric value is detected.

Methods

Static Private _formatNumericString

  • _formatNumericString(value: any, decimalDivider?: string): string
  • Format a given value to a numeric string. If the conversion is not possible, an exception will be thrown

    throws

    Error If the value is not numeric or if the decimal divider is invalid.

    Parameters

    • value: any

      A value to format

    • Default value decimalDivider: string = ""

      The decimal divider to use. possible values are '.' and ','. It will be auto detected If set to empty string

    Returns string

    The formatted numeric string.

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, decimalDivider?: string): number
  • Get the number represented by the given value

    Parameters

    • value: any

      A value to convert to a number

    • Default value decimalDivider: string = ""

      The decimal divider to use. Possible values are '.' and ','. If not provided, it will be auto-detected.

    Returns 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, decimalDivider?: string): boolean
  • Checks if the given value is numeric.

    Parameters

    • value: any

      A value to check.

    • Default value decimalDivider: string = ""

      The decimal divider to use. Possible values are '.' and ','. If not provided, it will be auto-detected.

    Returns boolean

    true if the given value is numeric, false otherwise.

Generated using TypeDoc