rust_decimal

Pure-Rust fixed-precision Decimal type for financial and monetary calculations

Library
Cargo
v1.42.1
1,328stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity76
Maintenance56
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture80
Code Quality84
Innovation75
Learning Curve70

rust_decimal implements a Decimal number type in pure Rust suitable for financial and fixed-precision calculations that require exact integral and fractional digits with no floating-point round-off error. It uses a 96-bit integer plus a scaling factor and sign bit representation (matching .NET’s System.Decimal layout), preserving trailing zeros and supporting up to 28-29 significant digits.

The crate offers a broad set of optional integrations — PostgreSQL and MySQL database drivers, Diesel ORM support, serde with multiple serialization strategies (string, float, arbitrary precision), no_std/alloc compatibility, ndarray arithmetic, and a compile-time dec! macro — making it a common building block anywhere Rust code needs exact decimal arithmetic (pricing, accounting, currency).

What You Get

  • A Decimal type with exact fixed-precision arithmetic (add, subtract, multiply, divide, rounding) and no floating-point round-off error
  • The dec! compile-time macro for ergonomic, validated decimal literals (dec!(25.12))
  • Database driver integrations for PostgreSQL (db-postgres, db-tokio-postgres), MySQL, and Diesel ORM (db-diesel-postgres, db-diesel-mysql)
  • Multiple serde serialization strategies — as string, float, or arbitrary precision — configurable per-field via feature flags
  • Optional maths feature for pow, ln, exp, log10 and other transcendental operations via the MathematicalOps trait
  • no_std + alloc support, plus rkyv, borsh, bytemuck, proptest, and rand integrations

Common Use Cases

  • Representing monetary amounts and prices in e-commerce, billing, and accounting systems without float rounding errors
  • Storing and querying exact decimal values in PostgreSQL/MySQL applications via the built-in database driver integrations
  • Serializing decimal values to JSON/other formats with precise control over string vs. float representation
  • Performing scientific or engineering fixed-precision arithmetic that needs more digits of precision than IEEE floats provide

Under The Hood

Architecture — The core Decimal type and its arithmetic are implemented in src/decimal.rs and src/ops/ (separate modules per operation), with src/maths.rs housing the optional transcendental-function feature, and dedicated integration modules (postgres.rs, mysql.rs, serde.rs, borsh.rs, wasm.rs, rand_0_9.rs/rand_0_10.rs) gated behind Cargo feature flags so consumers only compile in what they use. A separate macros crate implements the dec! compile-time literal macro as a proc-macro, and build.rs handles any platform-specific codegen.

Tech Stack — Nearly pure Rust (99.95% of the codebase) with an extensive feature-flag matrix (align16, alloc, borsh, bytemuck, c-repr, macros, maths, ndarray, rkyv, serde-float/serde-str/serde-arbitrary-precision, db-postgres/db-tokio-postgres/db-diesel-postgres/db-diesel-mysql) that lets the crate serve everything from no_std embedded contexts to full ORM-backed financial applications from a single dependency.

Code Qualitytests/decimal_tests plus dedicated test files per integration (postgres_tests.rs, serde_tests.rs, borsh_tests.rs, ndarray_tests.rs, proptest_tests.rs, rust_fuzz_tests.rs) give each feature its own coverage, and a fuzz/ directory plus rust-fuzz/proptest feature flags indicate active property-based and fuzz testing of the arithmetic core — appropriate rigor for a type used in monetary calculations where correctness is critical. The README explicitly documents that the main branch is unstable/pre-2.0 with breaking changes expected, while a maintained v1 branch stays backwards-compatible.

API Design — The dec!(1.23) macro and Decimal::from_str/Decimal::new constructors give multiple ergonomic entry points depending on whether values are known at compile time or come from parsed input, and operator overloading (+, -, *, /) lets Decimal values be used like any other numeric type. The tradeoff of the crate’s large feature-flag surface is that discovering the right combination of flags for a given integration (e.g. serde-with-str vs. serde-str vs. serde-float) requires reading fairly detailed documentation.

Used by 8 apps in this directory

Dart
74%
AGPL 3.0

AppFlowy

Productivity · Project Management · Collaboration

75,729

The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.

View details
66
Repo Health
81
Technical
66
Dependency
Built with
Dart74%
Rust24%
Updated 1 weeks ago
Rust
86%
Other

Arroyo

Data Engineering · Analytics

5,005

A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.

View details
86
Repo Health
74
Technical
62
Dependency
Built with
Rust86%
Updated 1 weeks ago
Rust
96%
Apache 2.0

InfluxDB

Databases · Analytics

31,705

Open-source time-series database built for real-time ingest, fast SQL queries, and embedded Python automation — powered by Apache Arrow and Parquet.

View details
86
Repo Health
76
Technical
72
Dependency
Built with
Rust96%
Updated yesterday
Rust
87%
AGPL 3.0

ParadeDB

Search · Databases · Analytics

9,175

Born out of Y Combinator's S2023 batch, ParadeDB is a Postgres extension that delivers Elasticsearch-quality BM25 search and real-time analytics without a separate search cluster to manage.

View details
88
Repo Health
87
Technical
71
Dependency
Built with
Rust87%
PLpgSQL12%
Updated today
Python
55%
Other

PostHog

Analytics · Monitoring · Developer Tools

37,777

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
67
Dependency
Built with
Python55%
TypeScript36%
Updated today
Java
92%
Apache 2.0

QuestDB

Databases · Analytics

17,263

A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.

View details
91
Repo Health
86
Technical
70
Dependency
Built with
Java92%
Updated today
Rust
31%
Other

Windmill

Automation · Developer Tools

17,577

Turn scripts into webhooks, workflows, and auto-generated UIs — the fastest self-hostable workflow engine, 13x faster than Airflow.

View details
91
Repo Health
82
Technical
66
Dependency
Built with
Rust31%
Svelte22%
TypeScript22%
Updated today
Python
61%
Apache 2.0

WrenAI

Analytics · AI Agents · Data Engineering

17,313

Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.

View details
91
Repo Health
91
Technical
69
Dependency
Built with
Python61%
Rust36%
Updated today

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