SCARP v0.0.6-alpha.20
Exact decimal arithmetic
Explicit constructors, typed arrays and rounded division.
Compiler: published alpha.20 · b1a9347f93540fdf95b0ddecba4adc55a3b4bb98
Unchanged upstream source: original program · original output (Apache-2.0).
Predict before running
Predict the result of rounding one-third to two decimal places.
decimal_exact.srp
pure funcra taxed(price: decimal, rate: decimal) -> decimal {
return price + price * rate;
}
bind total: decimal = taxed(decimal("199.99"), decimal("0.18"));
bind scores: array<decimal, 2> = [array: decimal("0.1"), decimal("0.2")];
print(decimal_format(total, 2, "half_even"));
print(scores[0] + scores[1]);
print(decimal_div_rounded(decimal("1"), decimal("3"), 2, "half_even"));
decimal_exact.stdout
235.99
0.3
0.33
Run on your computer
scarp verify tutorials/alpha20-exact-values/decimal_exact.srp
scarp exec tutorials/alpha20-exact-values/decimal_exact.srp
The website does not execute code in your browser. Compare local output against the fixture.
हिन्दी में अभ्यास
एक तिहाई को दो दशमलव स्थानों तक round करने पर क्या मिलेगा?