Create, calculate and format money in 👑 Nim language.
nimble install money
Nim library to make working with money safer, easier and fun!
If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634 -- Bill Karwin
- Framework agnostic
- Works with BigInts via
pkg/bigints
- Math Operations
+
,-
,*
,/
- Math Operations (mutable)
+=
-=
,*=
,/=
=>add
,sub
,multi
,div
- Money Formatting (including intl formatter)
- Money Exchange using 3rd party providers
Use defaultCurrency
option to change the default currency at compile-time. Example -d:defaultCurrency:49
(default) for EURO
import money
assert $(fmt("150")) == "EUR 1.50"
assert 2500.EUR == fmt"2500" # EUR 25.50
var
x = amount("150", EUR)
y = amount("150", EUR)
assert x + y == 300.EUR # EUR 3.00
x += y
assert x == 300.EUR # EUR 3.00
assert x + y > y # EUR 3.00 > EUR 1.50
var x = fmt("100")
assert $(x - fmt(50)) == "EUR 0.50"
Comparing x
to y
is easy!
var
x = 100.EUR
y = 150.EUR
assert x == 100.EUR
assert x < y
assert x >= 99.EUR
assert x != 100.USD
assert y > x
assert y >= 149.EUR
Dummy cart example available in /tests
- 🐛 Found a bug? Create a new Issue
- 👋 Wanna help? Fork it!
- 😎 Get €20 in cloud credits from Hetzner
- 🥰 Donate via PayPal address
This library is inspired from moneyphp/money.
Money | MIT license. Made by Humans from OpenPeeps for Supranim
Copyright © 2023 Supranim | OpenPeeps & Contributors — All rights reserved.