Options
All
  • Public
  • Public/Protected
  • All
Menu

Module number

Number Functions

numberDecimalPortion

  • numberDecimalPortion(numberGetFrom: number | string, removeTrailingZeros?: boolean): string
  • name

    numberDecimalPortion

    description

    Get number decimal portion.

    throws

    {TypeError}

    since

    0.1.39

    example
    numberDecimalPortion("0.000100", false); // ➜ '000100'
    
    example
    numberDecimalPortion("1"); // ➜ ''
    
    example
    numberDecimalPortion(5.123); // ➜ '123'
    
    example
    numberDecimalPortion(12345678.99); // ➜ '99'
    

    Parameters

    • numberGetFrom: number | string
    • removeTrailingZeros: boolean = true

    Returns string

numberRanged

  • numberRanged(numberLike: any, defaultNumber?: number, minimalNumber?: number, maximumNumber?: number, shouldBeInteger?: boolean): number
  • name

    numberRanged

    description

    Typecast variable to number wih minimum and maximum value

    summary

    import { numberRanged } from "@corefunc/corefunc/number/ranged";

    example

    numberRanged("99.5", 0, 1, 100); // => 99.5

    Parameters

    • numberLike: any
    • defaultNumber: number = 0
    • minimalNumber: number = ...
    • maximumNumber: number = ...
    • shouldBeInteger: boolean = false

    Returns number

numberRound

  • numberRound(value: number, precision: number): number
  • name

    numberRound

    description

    Returns the value of a number rounded to the nearest integer using precision parameter.

    example

    numberRound(1234.5678, 1); // 1234.6

    example

    numberRound(1234.5678, -1); // 1230

    Parameters

    • value: number
    • precision: number

    Returns number

numberZeroPad

  • numberZeroPad(numberToPad?: number | string, leadingLength?: number, decimalLength?: number): string
  • name

    numberZeroPad

    description

    Pad a number with leading zeros and zeroes after the decimal point.

    summary

    import { numberZeroPad } from "@corefunc/corefunc/number/zero-pad";

    throws

    {RangeError|TypeError}

    since

    0.1.39

    example
    numberZeroPad("0.0001", 3); // ➜ '000.0001'
    
    example
    numberZeroPad("1", 3, 2); // ➜ '001.00'
    
    example
    numberZeroPad(5.123, 4); // ➜ '0005.123'
    
    example
    numberZeroPad(1234567.89, 4, 3); // ➜ '1234567.890'
    

    Parameters

    • numberToPad: number | string = 0
    • leadingLength: number = 0
    • Optional decimalLength: number

    Returns string

Generated using TypeDoc