rust_decimal

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

Library
Cargo
v1.43.0
1,341 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
74 /100 Good
Development Activity 76
Maintenance 52
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
77 /100 Good
Architecture 80
Code Quality 84
Innovation 75
Learning Curve 70

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 Quality — tests/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 9 apps in this directory

Dart
74%
AGPL 3.0

AppFlowy

AI Assistants · Collaboration · Productivity

76,967

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
67
Dependency
Built with
Dart 74%
Rust 24%
Updated 1 weeks ago
Rust
86%
Other

Arroyo

Analytics · Data Engineering

5,039

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
Rust 86%
Updated 1 weeks ago
Rust
96%
Apache 2.0

InfluxDB

Analytics · Databases

31,758

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
82
Repo Health
76
Technical
72
Dependency
Built with
Rust 96%
Updated 1 weeks ago
Rust
86%
AGPL 3.0

ParadeDB

Analytics · Databases · Search

9,311

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
89
Repo Health
87
Technical
68
Dependency
Built with
Rust 86%
PLpgSQL 14%
Updated 4 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

39,975

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
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 4 days ago
Java
93%
Apache 2.0

QuestDB

Analytics · Databases

17,360

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
67
Dependency
Built with
Java 93%
Updated 4 days ago
TypeScript
67%
Apache 2.0

tabularis

Databases · Developer Tools

5,076

Open-source desktop SQL workspace with built-in PostgreSQL, MySQL, and SQLite drivers, SQL notebooks, a visual query builder, and a built-in MCP server for AI agents like Claude and Cursor.

View details
83
Repo Health
89
Technical
70
Dependency
Built with
TypeScript 67%
Rust 32%
Updated 5 days ago
Rust
32%
Other

Windmill

Automation · Developer Tools

18,043

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
65
Dependency
Built with
Rust 32%
TypeScript 24%
Svelte 22%
Updated 4 days ago
Python
65%
Apache 2.0

WrenAI

AI Agents · Analytics · Data Engineering

17,763

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
90
Repo Health
91
Technical
69
Dependency
Built with
Python 65%
Rust 32%
Updated 1 weeks ago

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