Skip to content
generated from supranim/temple

Create, calculate and format money in Nim language (WIP)

License

Notifications You must be signed in to change notification settings

openpeeps/money

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Create, calculate and format money in 👑 Nim language.

nimble install money

API reference
Github Actions Github Actions

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

😍 Key Features

  • 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

Examples

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

Math

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"

Comparisons

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

Cart Example

Dummy cart example available in /tests

❤ Contributions & Support

This library is inspired from moneyphp/money.

🎩 License

Money | MIT license. Made by Humans from OpenPeeps for Supranim
Copyright © 2023 Supranim | OpenPeeps & Contributors — All rights reserved.