Module Relude_Decimal
Relude.Decimal contains a type t which represents arbitrary precision numeric values, backed by an int mantissa and an int exponent. This can be useful for representing currency values without loss in precision or floating point errors.
Because the mantissa and exponent are backed by ints, there is a fairly restrictive range of values that can be represented.
let a = Decimal(12345, -2); // 123.45
let b = Decimal(6789, 3); // 6789000- type t- =
 ;- |- Decimal(mantissa, exponent)
- Represents an arbitrary precision number, backed by an integer mantissa, and integer exponent. 
- type rounding- =
 ;- |- Truncate- |- RoundUp- |- RoundDown- |- RoundUpOrDown
- Represents a preference for rounding a - Decimalvalue, when applicable.
- let make: int => int => t;
- Decimal.makeconstructs a- Decimalfrom a- mantissaand- exponent.
- let fromInt: int => t;
- Decimal.fromIntconstructs a- Decimalfrom an- int.
- let show: t => string;
- Decimal.fromStringattempts to parse a- Decimalfrom a- string- Decimal.showrenders the- Decimalvalue to a- string, as if the- Decimalwas represented as a- float.- Decimal(12345, -2) |> Decimal.toString // "123.45" Decimal(12345, 3) |> Decimal.toString // "12345000"
- let tenToThePowerOfPositive: int => int;
- Decimal.roundrounds a- Decimalusing the given rounding strategy.- Decimal.tenToThePowerOfPositivecomputes the value of- 10^exponent.- The return value of this function is undefined for exponent values < 0. - Decimal.tenToThePowerOf(3) == 1000;
- let normalize: t => t => (t, t, int);
- Decimal.normalizenormalizes the exponent to the minimal exponent for two given- Decimalvalues.- let a = Decimal(12345, -2); // 123.45 let b = Decimal(12345, 3); // 12345000 let res = Decimal.normalize(a, b); res == (Decimal(12345, -2), Decimal(1234500000, -2), -2)
- let add: t => t => t;
- Decimal.addadds two- Decimalvalues with no attempt at avoiding overflow.- Note: the arguments are in order of - lhs,- rhs.