Skip to content

money

Package money adds fixed-point currency scalar functions over the same exact base-10 backend as ext/decimal. Every result is rounded to two fractional digits, the granularity money is actually stored at, so chains of additions and multiplications don’t drift the way binary floats do.

money(x) -- round x to 2 dp (canonical money text)
money_add(a, b) -- round(a + b, 2)
money_sub(a, b) -- round(a - b, 2)
money_mul(a, b) -- round(a * b, 2) (e.g. price × quantity)
money_format(x[, s]) -- "$1,234.56" with thousands separators

Inputs may be TEXT / INTEGER / REAL (a REAL is read as the shortest decimal that round-trips it). Any NULL argument yields NULL.


Full API: pkg.go.dev/gosqlite.org/ext/money