new Money(float: number): TMoney<'XXX'>;
new Money<C extends CurrencyCode>(float: number, currency: C): TMoney<C>;
When working with scripts, it is preferable to use the constructor that specifies a particular currency:
const price = new Money(100.5, 'EUR');
Currency codes correspond to the [ISO 4217] standard (https://en.wikipedia.org/wiki/ISO_4217).
Values of this type are immutable, so mutation methods return
the updated value without changing the original one.
const price = new Money(100.5, 'EUR');
const total = price.multiply(count);
Type parameters
C: CurrencyCode
Hierarchy
TMoney
Properties
Readonly
cents
cents:number
Number of cents.
Readonly
currency
currency:C
Currency (alphabetic code from the ISO 4217 standard).
To avoid rounding errors, it is checked whether the currencies are different before the operation is executed.
If the currencies don’t match, the operation doesn’t proceed, and an error is returned.
Example:
const a = new Money(100.25, 'USD');
const b = new Money(200.75, 'USD');
const result = a.addm(b); // 301.00 USD
Money
The constructors are as follows:
new Money(float: number): TMoney<'XXX'>; new Money<C extends CurrencyCode>(float: number, currency: C): TMoney<C>;When working with scripts, it is preferable to use the
constructor that specifies a particular currency:
const price = new Money(100.5, 'EUR');Currency codes correspond to the [ISO 4217] standard (https://en.wikipedia.org/wiki/ISO_4217). Values of this type are immutable, so mutation methods return the updated value without changing the original one.
const price = new Money(100.5, 'EUR'); const total = price.multiply(count);Type parameters
C: CurrencyCode
Hierarchy
Properties
Readonly cents
Number of cents.
Readonly currency
Currency (alphabetic code from the ISO 4217 standard).
Methods
add Deprecated
Adding money values.
Use TMoney.addm that guarantees precise calculations and checks whether currencies match.
Use TMoney.addm that guarantees precise calculations and checks whether currencies match.
Parameters
money: TMoney<C | "XXX">
Returns TMoney<C>
addm
Adding money values with guaranteed precision.
To avoid rounding errors, it is checked whether the currencies are different before the operation is executed. If the currencies don’t match, the operation doesn’t proceed, and an error is returned. Example:
const a = new Money(100.25, 'USD'); const b = new Money(200.75, 'USD'); const result = a.addm(b); // 301.00 USDError — If currencies don’t match.
Parameters
money: TMoney<C | "XXX">
Returns TMoney<C>
asFloat
Decimalization with an accuracy depending on the currency.
const salary = new Money(101, 'USD'); const salary2 = salary. multiply(0,001); salary2.asFloat(); // 0.1Returns number
multiply
Multiply by the number, rounding down the cents.
Parameters
k: number
Returns TMoney<C>
Feedback sent successfully
Thank you for your input