Reference · Decimals and money

money.is_zero

signature
money.is_zero(map) -> bool

What it does

Whether an amount is nothing: true for zero in any currency, false for any other amount, positive or negative. It asks the amount's value, not its digits, so 0, 0.00 and -0.00 are all zero.

Examples

print(money.is_zero(money.zero("USD")), money.is_zero(money.of("0.01", "USD")))let a = money.of("10.25", "USD")print(money.is_zero(money.sub(a, a)), money.is_zero(money.neg(a)))
output
true falsetrue false

Edge cases

print(money.is_zero({ amount: "0.000", currency: "USD" }), money.is_zero({ amount: 0, currency: "JPY" }), money.is_zero(money.of("-0.00", "USD")))print(money.is_zero(money.mul(money.of("0.01", "USD"), dec("0.5"))))
output
true true truetrue

Errors

A value that is not money is a runtime error, not an error value: money.is_zero(0) stops the request, since 0 is a number, not an amount. So does a map with more decimals than its currency has.

this one fails
print(money.is_zero(0))
output
line 1: `money.is_zero` expects money ({ amount, currency }) as argument 1, got int 0
this one fails
print(money.is_zero({ amount: "0.001", currency: "USD" }))
output
line 1: `money.is_zero`: 0.001 has more decimals than USD has (2): round it first with money.round(m, mode)

Chaining

let paid = [money.of(0, "USD"), money.of("2.50", "USD"), money.zero("USD")]print(paid | filter(money.is_zero) | len)print(money.of(5, "USD") | money.sub(money.of(5, "USD")) | money.is_zero)
output
2true

See also

money.zero, money.compare, money.sub, money.neg

Thread
5Useful? Like it, or add to its thread below.

Thread 0 posts

On money.is_zero(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo