Aller au contenu principal

BigDecimal

A collection of functions to manipulate BigDecimal

Index

Codec

codecDecode

  • codecDecode(this: void, input: unknown, context: Context<BigDecimal>): Result<BigDecimal, CodecError>
  • Returns the decoded input, Result.Ok or Result.Error()

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const input: unknown = ...;
    const decoded = Codec.decode(someCodec, input);

codecEncode

  • codecEncode(this: void, input: BigDecimal): unknown
  • Returns the encoded input

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const someObject: SomeObject = { foo: "bar" }
    const encoded = Codec.decode(someCodec, someObject);

codecSchema

  • codecSchema(this: void): JSONValue
  • Returns the JSONSchema corresponding to the decoded type

    @example
    const someCodec: Codec<unknown> = ...;
    const jsonSchema = Codec.schema(someCodec);

Comparator

!=

  • !=(this: void, left: BigDecimal, right: BigDecimal): boolean
  • "Not equal to" operator

    @example
    const TEqual: Equal<T>;
    TEqual['!='](value, otherValue); // true
    TEqual['!='](value, value); // false

  • (this: void, left: BigDecimal, right: BigDecimal): boolean
  • "Less than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<'](smallerT, smallerT); // false
    TCompare['<'](smallerT, greaterT); // true
    TCompare['<'](greaterT, smallerT); // false

<=

  • <=(this: void, left: BigDecimal, right: BigDecimal): boolean
  • "Less than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<='](smallerT, smallerT); // true
    TCompare['<='](smallerT, greaterT); // true
    TCompare['<='](greaterT, smallerT); // false

==

  • ==(this: void, left: BigDecimal, right: BigDecimal): boolean
  • "Equal to" operator

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual['=='](value, value); // true
    TEqual['=='](value, otherValue); // false

  • (this: void, left: BigDecimal, right: BigDecimal): boolean
  • "Greater than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>'](smallerT, smallerT); // false
    TCompare['>'](smallerT, greaterT); // false
    TCompare['>'](greaterT, smallerT); // true

>=

  • >=(this: void, left: BigDecimal, right: BigDecimal): boolean
  • "Greater than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>='](smallerT, smallerT); // true
    TCompare['>='](smallerT, greaterT); // false
    TCompare['>='](greaterT, smallerT); // true

clamp

  • clamp(this: void, value: BigDecimal, minValue: BigDecimal, maxValue: BigDecimal): BigDecimal
  • Clamp value between minValue and maxValue

    @example
    type T;
    const TCompare: Comparable<T>;
    TCompare.clamp(value, min, max); // min if value < min, max if value > max, otherwise value itself

compare

  • compare(this: void, left: BigDecimal, right: BigDecimal): number
  • Return a number that represents comparison

    @example
    type T;
    const TCompare: Comparable<T>;
    const sorted = [3, 1, 1].sort(TCompare.compare);

equals

  • equals(this: void, left: BigDecimal, right: BigDecimal): boolean
  • Alias to '=='

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual.equals(value, value); // true
    TEqual.equals(value, otherValue); // false

max

  • max(this: void, left: BigDecimal, right: BigDecimal): BigDecimal
  • "maximum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.max(smallerT, greaterT); // greaterT

min

  • min(this: void, left: BigDecimal, right: BigDecimal): BigDecimal
  • "minimum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.min(smallerT, greaterT); // smallerT

Constructor

asInstance

  • asInstance(anyValue: unknown): Option<BigDecimal>
  • Try to convert anyValue to enum value or else returns Option.None

    @example
    const StringType: Type<string>;
    StringType.asInstance('foo'); // Option.Some('foo')
    StringType.asInstance(12); // Option.None

create

  • create(this: void, properties: Parameters<BigDecimal>): BigDecimal
  • Construct a new model

of

  • of(value: bigint, scale: number): BigDecimal
  • Returns a new BigDecimal from value and scale

    @example
    BigDecimal.of(1n, 1); // BigDecimal('0.1')
    BigDecimal.of(-234n, 2); // BigDecimal('2.34')

Numeric

*

  • *(left: BigDecimal, right: BigDecimal): BigDecimal
  • Multiplication operator

    @example
    type T = ...;
    const TNumeric: Numeric.Multiply<T> = ...;
    const result = Numeric['*'](left, right);// represents (left * right)

+

  • +(left: BigDecimal, right: BigDecimal): BigDecimal
  • Addition operator

    @example
    type T = ...;
    const TNumeric: Numeric.Add<T> = ...;
    const result = TNumeric['+'](left, right);// represents (left + right)

-

  • -(left: BigDecimal, right: BigDecimal): BigDecimal
  • Subtraction operator

    @example
    type T = ...;
    const TNumeric: Numeric.Subtract<T> = ...;
    const result = Numeric['-'](left, right);// represents (left - right)

abs

  • abs(value: BigDecimal): BigDecimal
  • Absolute value. It should satisfy Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == x

    @example
    type T = ...;
    const TSigned: Numeric.Signed<T> = ...;
    const result = TSigned.abs(value);// absolute value of (value)

sign

  • sign(value: BigDecimal): BigDecimal
  • Sign of a number. It should satisfy TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == x

Type

inspect

inspect: Option<(anyValue: BigDecimal, depth: number, options: InspectOptions, inspect: InspectFunction) => string>

When defined, returns a custom string representation

@example

@param

readonlytypeName

typeName: BigDecimal

The factory type constant

hasInstance

  • hasInstance(anyValue: unknown): anyValue is BigDecimal
  • Return true if the given value is an instance of the class.

    @example
    const StringType: Type<string>;
    StringType.hasInstance('foo'); // true
    StringType.hasInstance(42); // false

Other

__call__

  • __call__(stringValue: `${number}`): BigDecimal
  • __call__(value: bigint, scale?: number): BigDecimal

format

  • format(bigDecimal: BigDecimal): string
  • Returns a string representation of a BigDecimal

    @example
    BigDecimal.format(BigDecimal('1.020')); // '1.020'

normalize

  • normalize(value: BigDecimal): BigDecimal
  • Returns a normalized value

    @example
    BigDecimal.normalize(BigDecimal('1.020')); //  BigDecimal('1.02')
    BigDecimal.normalize(BigDecimal('1.0200')); // BigDecimal('1.02')

parse

  • parse(expression: string): Option<BigDecimal>
  • Returns a new BigDecimal from a string

    @example
    BigDecimal.parse('1.020'); // Option.Some(BigDecimal('1.020'))
    BigDecimal.parse('A'); // Option.None

scale

  • scale(value: BigDecimal, newScale: number): BigDecimal
  • Scales a given BigDecimal to the specified scale.

    @example
    const value = BigDecimal('1.02');
    BigDecimal.scale(value, 1); // BigDecimal('1.0')
    BigDecimal.scale(value, 3); // BigDecimal('1.020')