Crates.io | cashmoney |
lib.rs | cashmoney |
version | |
source | src |
created_at | 2024-12-13 00:02:06.330752 |
updated_at | 2024-12-13 00:02:06.330752 |
description | Library for safe monetary calculations |
homepage | https://github.com/arcanyx-pub/cashmoney-rs |
repository | https://github.com/arcanyx-pub/cashmoney-rs |
max_upload_size | |
id | 1481756 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Cashmoney is a Rust library for expressing monetary values and performing safe monetary calculations suitable for financial applications.
let value = dec!(13.37);
let a: Result<Money> = Money::from(value, Currency::USD);
assert_eq!(a, b);
// Convenience macros. Note that these macros rely on the rust_decimal crate's
// `dec!` macro to parse the values.
let c = cad!(13.37;
let d = usd!(13.37);
let sum: Money = usd!(13) + usd!(0.37);
assert_eq!(sum, usd!(13.37));
// Returns Err:
let _ = usd!(13) + cad!(0.37);
let difference: Money = usd!(14.00) - usd!(0.63);
assert_eq!(difference, usd!(13.37));
// FractionalMoney represents a monetary value that may be a more precise value
// than the smallest denomination for the given currency. For example, the
// value below would be USD $6.685.
let product: FractionalMoney = usd!(13.37) * dec!(0.5);
assert_eq!(product.fractional_value(), dec!(6.685));
// "Standard" rounding (midpoint rounds away from zero)
let rounded_up: Money = product.round_up();
assert_eq!(rounded_up, usd!(6.69));
// "Banker's rounding"
let rounded: Money = product.round();
assert_eq!(rounded, usd!(6.68));