# MidaDecimal()

Decimal numbers and calculations are accurately represented by the MidaDecimal class.


Since computers can only store integers directly, they require a method to represent decimal numbers. However, this representation is not entirely precise. As a result, in many programming languages, performing calculations like 0.1 + 0.2 may not yield an exact value of 0.3. This lack of accuracy can be particularly problematic in financial and monetary calculations, potentially leading to irreversible losses. In Mida, decimal numbers and calculations are safe by design

  • Interface
class MidaDecimal {
    constructor (value: MidaDecimalConvertible, digits: number);
    add (operand: MidaDecimalConvertible): MidaDecimal;
    sub (operand: MidaDecimalConvertible): MidaDecimal;
    mul (operand: MidaDecimalConvertible): MidaDecimal;
    div (operand: MidaDecimalConvertible): MidaDecimal;
    eq (operand: MidaDecimalConvertible): boolean;
    greaterThan (operand: MidaDecimalConvertible): boolean;
    greaterThanOrEqual (operand: MidaDecimalConvertible): boolean;
    lessThan (operand: MidaDecimalConvertible): boolean;
    lessThanOrEqual (operand: MidaDecimalConvertible): boolean;

    toFixed (digits: number): MidaDecimal;
    toNumber (): number;
    toString (): string;

    static abs (operand: MidaDecimal): MidaDecimal;
    static min (...operands: MidaDecimalConvertible[]): MidaDecimal;
    static max (...operands: MidaDecimalConvertible[]): MidaDecimal;