Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

  • almostEqual(n: number, e?: number): boolean
  • Test for near-equivalence of two numbers within some permitted epsilon

    Parameters

    • n: number

      Some other number

    • e: number = 1e-8

      Some permitted epsilon, by default 1e-8

    Returns boolean

    Are the numbers almost equal?

  • ordinalString(): string
  • Transform a number to an ordinal string representation. i.e. 1 => 1st 2 => 2nd 3 => 3rd

    Returns string

  • paddedString(digits: number): string
  • Return a string front-padded by zeroes to reach a certain number of numeral characters

    Parameters

    • digits: number

      The number of characters desired

    Returns string

    The zero-padded number

  • signedString(): string
  • Return a string prefaced by the sign of the number (+) or (-)

    Returns string

    The signed number as a string

  • toNearest(interval?: number, method?: string): number
  • Round a number to the nearest number which is a multiple of a given interval

    example

    Round a number to the nearest step interval

    let n = 17.18;
    n.toNearest(5); // 15
    n.toNearest(10); // 20
    n.toNearest(10, "floor"); // 10
    n.toNearest(10, "ceil"); // 20
    n.toNearest(0.25); // 17.25

    Parameters

    • interval: number = 1

      The interval to round the number to the nearest multiple of

    • method: string = "round"

    Returns number

    The rounded number

  • between(a: number, b: number, inclusive?: boolean): boolean
  • A faster numeric between check which avoids type coercion to the Number object. Since this avoids coercion, if non-numbers are passed in unpredictable results will occur. Use with caution.

    Parameters

    • a: number

      The lower-bound

    • b: number

      The upper-bound

    • inclusive: boolean = true

      Include the bounding values as a true result?

    Returns boolean

    Is the number between the two bounds?

  • isNumeric(n: any): boolean
  • Test whether a value is numeric. This is the highest performing algorithm currently available, per https://jsperf.com/isnan-vs-typeof/5

    memberof

    Number

    Parameters

    • n: any

      A value to test

    Returns boolean

    Is it a number?

  • fromString(n: string | number): number
  • Attempt to create a number from a user-provided string.

    memberof

    Number

    Parameters

    • n: string | number

      The value to convert; typically a string, but may already be a number.

    Returns number

    The number that the string represents, or NaN if no number could be determined.