Crate accounting

Source
Expand description

accounting is a library for money and currency formatting.

§Examples

let mut ac = Accounting::new_from("$", 2);
ac.set_format("{s} {v}");
assert_eq!(ac.format_money(1000000), "$ 1,000,000.00");
assert_eq!(ac.format_money(-5000), "-$ 5,000.00");

Set the format string of Accounting variable,then format numbers as money values. In the format string:

  • {v} is placehoder of value, will be replaced by number.
  • {s} is placehoder of symbol, will be replaced by currency symbol like $、¥ and so on.
#[cfg(feature="decimal")]
fn format_decimal_type() {
	let mut ac = Accounting::new_from("$", 2);
	ac.set_format("{s} {v}");
	let x = rust_decimal::Decimal::new(-12345678921, 2);
    assert_eq!(ac.format_money(x), "-$ 123,456,789.21"); 
}

If you want use decimal numbers,enable feature decimal,than you can use decimal number supported by rust_decimal lib. like above.

Re-exports§

Modules§

Structs§

  • Format numbers as money values according to settings.