Options
All
  • Public
  • Public/Protected
  • All
Menu

Module decimal

Index

Functions

abs

  • Calculate the absolute value of the decimal

    example
    import * as decimal from 'decimal';
    let d = decimal.newFromString('-123.4567');  // d is -123.4567
    decimal.abs(d)  // 123.4567
    

    Parameters

    Returns Decimal

avg

  • Calculate the average of multiple decimal values

    example
    import * as decimal from 'decimal';
    let d = decimal.newFromString('-123.4567');
    let e = decimal.newFromString('-12.467');
    decimal.avg(d,e)
    

    Parameters

    • first: Decimal

      the first decimal value

    • Rest ...decs: Decimal[]

      the rest decimal values

    Returns Decimal

fmtCurrency

  • fmtCurrency(value: number, precision: number, format: string, symbol: string, decimal: string, thousand: string): string
  • Format currency value with currency symbol, etc.

    example
    
    import * as decimal from 'decimal';
    let money = decimal.fmtCurrency(1234.123,2,"s nv","$", ".", ",");
    

    Parameters

    • value: number

      currency value.

    • precision: number

      number of decimal places to be reserved. The default value is 2.

    • format: string

      currency information display format, for example, the position relationships between currency symbols, negative values, and values.

    • symbol: string

      currency symbol. Example: $

    • decimal: string

      symbol of the decimal point. The default value is .

    • thousand: string

      thousands separator symbol. The default value is ,

    Returns string

    Formatted currency expression character string.

fmtOrgCurrency

  • fmtOrgCurrency(value: number, isoCode: string): string
  • format currency value with organization format

    example
    
    import * as decimal from 'decimal';
    let money = decimal.fmtOrgCurrency(1234.123,"USD");
    

    Parameters

    • value: number

      currency value.

    • isoCode: string

      The currency type (USD or CNY) must be one of the company's currency types. If this parameter is left empty, the currency type of the current user is used.

    Returns string

max

  • Get the maximum value of multiple decimal values

    example
    import * as decimal from 'decimal';
    let d = decimal.newFromString('-123.4567');
    let e = decimal.newFromString('-12.467');
    decimal.max(d,e)
    

    Parameters

    • first: Decimal

      the first decimal value

    • Rest ...decs: Decimal[]

      the rest decimal values

    Returns Decimal

min

  • Get the minimum value of multiple decimal values

    example
    import * as decimal from 'decimal';
    let d = decimal.newFromString('-123.4567');
    let e = decimal.newFromString('-12.467');
    decimal.min(d,e)
    

    Parameters

    • first: Decimal

      the first decimal value

    • Rest ...decs: Decimal[]

      the rest decimal values

    Returns Decimal

newFromFloat

  • newFromFloat(value: number): Decimal
  • Craete decimal value from number value

    example
    
    let d = decimal.newFromFloat(13.135); // d is 13.135
    

    Parameters

    • value: number

      the number value

    Returns Decimal

newFromString

  • newFromString(value: string): Decimal
  • Create decimal value from digital string

    example
    
    let d = decimal.newFromString('-123.4567'); // d is -123.4567
    

    Parameters

    • value: string

      the digital string

    Returns Decimal

newWithExponent

  • newWithExponent(value: number, exp: number): Decimal
  • Create decimal value use exponent

    example
    
    let d = decimal.newWithExponent(1.234567, 3); // d is 3^1.234567
    

    Parameters

    • value: number

      the base value

    • exp: number

      the exponent

    Returns Decimal

numberFormat

  • numberFormat(format: string, value: number | Decimal): string
  • Numerical formatting

    example
    
    decimal.numberFormat('0', 3.1415927)            // 3
    decimal.numberFormat('0.0', 3.1415927)          // 3.1
    decimal.numberFormat('0.00', 3.1415927)         // 3.14
    decimal.numberFormat('#.##%', 100 * 3.1415927)  // 314.16%
    decimal.numberFormat('00.000', 3.1415927)       // 03.142
    decimal.numberFormat('#.#####e0', 299792458)    // 2.99792E+08
    decimal.numberFormat(',###', 299792458)         // 299,792,458
    decimal.numberFormat('$,###.##',1234556)        // $1,234,556
    decimal.numberFormat('0.00', 11.1)              // 11.10
    

    Parameters

    • format: string

      the format to be used

    • value: number | Decimal

      the number or Decimal to be formatted

    Returns string

toNumber

  • toNumber(d: any): number
  • Convert decimal.Decimal type to number value

    example
    import * as decimal from 'decimal';
    let d = decimal.newFromString('-123.4567');
    decimal.toNumber(d)
    

    Parameters

    • d: any

    Returns number

zero

  • Create zero decimal value

    example
    
    let z = decimal.zero();
    

    Returns Decimal