#decimal #decimal-number #finance

const-decimal

Integer-backed decimals with constant precision

5 unstable releases

0.3.0 Oct 13, 2024
0.2.2 Sep 15, 2024
0.2.1 Sep 15, 2024
0.2.0 Sep 15, 2024
0.1.0 Sep 13, 2024

#898 in Math

Download history 284/week @ 2024-09-09 216/week @ 2024-09-16 3/week @ 2024-09-23 2/week @ 2024-09-30 109/week @ 2024-10-07 68/week @ 2024-10-14 5/week @ 2024-11-04

180 downloads per month

MIT/Apache and maybe LGPL-3.0-only

51KB
1K SLoC

Const Decimal

const-decimal is a fixed precision decimal backed by an underlying integer. This means it can compute Add/Sub/Mul/Div* operations within it's range without precision loss. This crate was created as there was no pre-existing crate that offered these features for decimal numbers (fixed cannot represent decimals with precision).

This is a fairly simple crate and is mainly intended to serve as a lossless representation of decimal values. While math operations are supported it is not intended to be a general purpose maths library.

* Division can of course truncate like normal division.

Goals

The goals in order of priority are:

  • Safety: Panic on over/underflow (even in release).
  • Precision: Use integers instead of floats.
  • Performance: Use primitive underlying types were possible.

Dependencies

~0.8–2.5MB
~50K SLoC