decimal

Generated by tinox doc

A string-backed fixed-scale decimal type for arithmetic where float rounding is unacceptable (e.g. money). add/subtract/multiply track scale automatically; divide currently only returns a zero placeholder at the requested precision.

ModuleVersionGroup
string1.0.0tinox.core

Money arithmetic

import tinox.core.decimal;

class Main
{
    fnc main() -> Int32
    {
        let price: Decimal = Decimal::fromInt(1999);
        let tax: Decimal = Decimal::fromInt(160);

        let total: Decimal = Decimal::add(price, tax);
        println(Decimal::toString(total));

        let discounted: Decimal = Decimal::subtract(total, Decimal::fromInt(500));
        println(Decimal::toString(discounted));

        return 0;
    }
}

class Decimal

Fields

valueString
scaleInt64

Methods

fn new(value: String) → Decimal
fn fromInt(value: Int64) → Decimal
fn fromFloat(value: Float64) → Decimal
fn add(a: Decimal, b: Decimal) → Decimal
fn subtract(a: Decimal, b: Decimal) → Decimal
fn multiply(a: Decimal, b: Decimal) → Decimal
fn divide(a: Decimal, b: Decimal, precision: Int64) → Decimal
fn scaleValue(value: String, digits: Int64) → String
fn addStrings(a: String, b: String) → String
fn subtractStrings(a: String, b: String) → String
fn multiplyStrings(a: String, b: String) → String
fn toString(d: Decimal) → String