use-amount 0.1.0

Decimal-safe scaled integer amount primitives for RustUse finance crates
Documentation
  • Coverage
  • 100%
    22 out of 22 items documented1 out of 15 items with examples
  • Size
  • Source code size: 12.26 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 452.06 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • RustUse/use-finance
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • CloudBranch

use-amount

Decimal-safe scaled integer amount primitives for RustUse finance crates.

use-amount stores financial amounts as integer minor units plus a decimal scale. It avoids f32 and f64 entirely.

Example

use use_amount::Amount;

let invoice = Amount::from_minor_units(12_345, 2)?;
let payment = Amount::from_minor_units(2_345, 2)?;
let balance = invoice.checked_sub(payment)?;

assert_eq!(invoice.to_string(), "123.45");
assert_eq!(balance.minor_units(), 10_000);
# Ok::<(), Box<dyn std::error::Error>>(())

Scope

Use this crate for scaled integer amount values, checked same-scale arithmetic, sign checks, rescaling, normalization, and formatting. It does not model currencies, money, exchange rates, taxes, or rounding policy engines.

License

Licensed under either MIT or Apache-2.0.