decimal-money
Money types for Rust — CurrencyAmount with Decimal precision, multi-currency support, FX conversion, and formatting.
Features
- Decimal precision — Uses
rust_decimalfor exact arithmetic - 36+ currencies — Fiat and crypto (USD, EUR, GBP, JPY, BTC, ETH, ...)
- FX conversion — Pluggable
FxProvidertrait with in-memory implementation - Formatting — Configurable symbol position, separators, ISO codes
- Type-safe — Currency mismatch errors at runtime, not panics
Quick Start
use ;
let price = new;
let tax = new;
let total = .unwrap;
assert_eq!;
assert_eq!;
Formatting
use ;
let amount = new;
// US style: $1,234.56
let us = us;
// European style: 1.234,56 €
let eu = european;
assert_eq!;
FX Conversion
use ;
use Decimal;
let mut provider = new;
provider.set_rate;
let dollars = new;
let euros = convert.unwrap;
Comparison with Manual rust_decimal Usage
Without money, you'd track currency manually:
use Decimal;
let amount = from; // cents
let currency = "USD";
// ... hope you don't mix up currencies
With money, you get:
CurrencyAmountbundles amount + currency- Arithmetic checks currency compatibility
- Formatting handles symbols and decimal places
- No "stringly-typed" currency codes in your business logic
License
Licensed under either of MIT or Apache-2.0 at your option.