Complex Expressions

Real compound expressions — multi-item discounts, threshold discounts, tax rates, commissions, compound interest — evaluated precisely throughout.

Complex Expressions

Real-world compound expressions — multi-item discounts, threshold discounts, tax rates, commissions, compound interest — where native floating-point arithmetic accumulates errors at intermediate steps. calc uses BigInt for exact evaluation throughout.

All results below are cross-validated against mathjs high-precision evaluation (see test cases in packages/main/tests/calc.test.ts).

Try It Live

calc('(999.99 * 3 + 499.5 * 2 + 199.9 * 5) * 0.85 - 200') // multi-item 15% off then subtract 200
calc('((85000 - 5000) * 0.8 + 5000) * 0.13 + 1000 * 0.06') // tax + commission
calc('100000 * 1.004 * 1.004 * 1.004 * 1.004 * 1.004 * 1.004 - 100000') // compound interest
在线运行⌘/Ctrl + Enter 运行

Discounts / Threshold Discounts

calc
('0.1 + 0.2 + 0.3 + 0.4 + 0.5 + 0.6 + 0.7 + 0.8 + 0.9') // "4.5"
calc
('(999.99 * 3 + 499.5 * 2 + 199.9 * 5) * 0.85 - 200') // "4048.6995"
calc
('(128.8 * 2 + 256.6 * 3 + 64.4 * 5 + 512.2) * 0.92 - 50') // "1662.672"
calc
('(2999 - 500) * 0.88 * 0.95 * 0.98 + 15 * 3') // "2092.38072"

Tax Rates / Commissions / Nested Arithmetic

calc
('((85000 - 5000) * 0.8 + 5000) * 0.13 + 1000 * 0.06') // "9030"
calc
('((1000 + 500) * 2 - 300) / 4 + (800 - 200) * 1.5 / 3') // "975"

Compound Interest

// Principal 100,000, monthly rate 0.4%, interest after 6 periods
calc
('100000 * 1.004 * 1.004 * 1.004 * 1.004 * 1.004 * 1.004 - 100000') // "2424.1283846148096"

Repeating Decimals (High-precision Division)

Division by 3, 7, etc. produces repeating decimals. calc retains 50 digits by default; use _fmt to truncate:

calc
('1000 / 3 + 2000 / 7 + 3000 / 11 + 4000 / 13 + 5000 / 17', {
_fmt
: {
decimals
: 10 } }) // "1493.5848465260"
calc
('10000 / 7.25 * 1.08 / 0.92 * 7.25 / 1.05', {
_fmt
: {
decimals
: 10 } }) // "11180.1242236024"
calc
('((299.9 + 399.9 + 599.9) * 2 + 99.9 * 5) / 3 * 0.95', {
_fmt
: {
decimals
: 10 } }) // "981.3183333333"