rusty-money

Handle monetary values in Rust with ISO-4217 currencies, precise arithmetic, formatting, and exchange.

Library
Cargo
v0.5.0
104stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
44/100Fair
Development Activity4
Maintenance20
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture80
Code Quality82
Innovation82
Learning Curve78

rusty-money is a library for representing and manipulating monetary values in Rust. It handles the notoriously error-prone parts of working with money - rounding, precision, locale-aware parsing and formatting, currency definitions, and exchange rates - following ISO-4217 currency standards and Martin Fowler’s money pattern. It offers both a high-precision 128-bit decimal Money type and a faster 64-bit FastMoney type, so you can trade precision for speed where it matters.

What You Get

  • A 128-bit decimal Money type for high-precision monetary arithmetic
  • A 64-bit FastMoney type that is several times faster for performance-critical paths
  • 150+ built-in ISO-4217 currencies and cryptocurrencies, plus the ability to define your own
  • Locale-aware formatting and parsing for international display
  • An Exchange type for managing rates and converting between currencies

Common Use Cases

  • Calculating prices, taxes, and totals without floating-point rounding errors
  • Splitting a bill or invoice fairly across multiple parties with allocated remainders
  • Formatting monetary amounts for different locales and currencies

Under The Hood

Architecture

The library separates a currency abstraction from the amount representation. A Currency carries ISO-4217 metadata - code, exponent, symbol, and locale rules - and lives in a set registry, while Money pairs a rust_decimal value with a currency reference. FastMoney mirrors the same interface over a 64-bit integer of minor units. Arithmetic, allocation, and formatting are implemented against these types, and Exchange holds a table of ExchangeRate entries used to convert Money between currencies.

Tech Stack

Built on the rust_decimal crate for 128-bit fixed-precision math, with optional serde support for serialization and proptest for property-based testing. It is a pure library with no runtime services, targeting stable Rust, and includes criterion benchmarks under benches to guard the FastMoney performance claims.

Code Quality

The codebase is small and disciplined, spanning about ten source files with eight test files plus property-based regressions checked into proptest-regressions. Fallible operations return Result and precision-losing methods are named explicitly, reflecting the stated safety-by-default principle. A CHANGELOG tracks releases and the API surface is documented on docs.rs.

API Design

The API reads naturally - Money::from_major, from_minor, add, and split map directly to how people reason about money - and runtime currency checks avoid heavy generic constraints, keeping call sites clean. Three focused entry points (Money, FastMoney, Exchange) make the surface easy to learn, and the quickstart gets you doing real arithmetic in a few lines.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search