Crate currency_rs

source ·
Expand description

A library for handling currencies

When working with currencies, decimals only need to be precise up to the smallest cent value while avoiding common floating point errors when performing basic arithmetic. currency_rs resolves this issue by working with vodo behind the scenes, so you don’t have to be concerned about decimal precision.

Quick startup

use currency_rs::{Currency, CurrencyOpts};
  
let item_price = 1.33;
let qty = 3.;
let flat_discount = 10.;

let cur_opts = Some(
    CurrencyOpts::new()
        .set_pattern("$ #")
        .set_precision(2)
        .set_increment(0.001),
);

let mut cur = Currency::new_float(item_price, cur_opts);

cur *= qty;

if cur.value() > 30. {
    cur -= flat_discount;
}
  
let final_total = cur.format();
  
println!("Final Total: {}", final_total);

Structs

Enums