NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io · #679 most downloaded on crates.io
Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
Last release 1 months ago
02 Sep 2026
Ships fairly regularly
a new release about every 3 months
Nearly every release is documented
notes for 59 of the last 60 stable releases
1 version withdrawn
withdrawn after publishing
10 years old
107 releases · first in 2016
Accumulated fixes backported from master by @paupino in #808
array_string by @flisky in #823Full Changelog: 1.42.1...1.43.0
One column per quarter.
fix: subtraction using carry-propogation can generate incorrect results by @paupino in #804
Full Changelog: 1.42.0...1.42.1
Optimize core arithmetic operations (+, -, *, /) by @paupino in #794
Full Changelog: 1.41.0...1.42.0
Replace ryu with zmij for float formatting by @hugobast in #772
rust-decimal by @ChristianIvicevic in #650Full Changelog: 1.40.0...1.41.0
Fixed Issue #760 serde_json roundtrip on specific values (0.0, 1.0, 2.0,...) by @hugobast in #761
v1 postgres -> postgres_backend by @Logarithmus in #751
postgres -> postgres_backend by @Logarithmus in #751Full Changelog: 1.38.0...1.39.0
Add new align16 feature to force 16 byte alignment for Decimal by @Tony-Samuels in #735
#[inline] to Decimal::from_parts (v1 backport) by @finnbear in #744Full Changelog: 1.37.2...1.38.0
More efficient is_zero check | v1 by @ivanrg99 in #719
Full Changelog: 1.37.1...1.37.2
[Docs] Includes macro information in published documentation by @paupino in #716
Full Changelog: 1.37.0...1.37.1
Bumps diesel version by @Dylan-DPC in #677
f64 dec limit edge case by @finnbear in #678maths feature by @olgabot in #681dec!() macro by example by @daniel-pfeiffer in #692dec!() macro by @paupino in #711Full Changelog: 1.36.0...1.37.0
Deprecate diesel1 feature and upgrade diesel to v2.2 by @paupino in #663
Full Changelog: 1.35.0...1.36.0
Nothing published for this version
Fixes an issue where when hydrating an underflowing NUMERIC value from PostgreSQL it would sometimes generate an invalid Decimal
NUMERIC value from PostgreSQL it would sometimes generate an
invalid
Decimal (#647)Deprecate macros feature until circular dependency issue is resolved properly.
macros feature until circular dependency issue is resolved properly.Hotfix for circular dependency when using the macros feature.
macros feature.rust_decimal_macros can now be utilized using the macros feature flag.
rust_decimal_macros can now be utilized using the macros feature
flag. (#628)pow function to more effectively handle larger
exponents (#638)Decimal from a string when a decimal point or placeholder is at the rounding
position (#636)Thank you to @robjtede and @schungx for your contributions this release.
Last but not least, a special thank you to @Tony-Samuels for your help with
managing rust_decimal!
Fixes an issue when converting from a Decimal to a float whereby the float would be inaccurate after rounding.
Decimal to a float whereby the float would be inaccurate after
rounding. (#625)Fixes an issue when adding/subtracting two Decimals when one has a scale of
Decimals when one has a scale of
29. (#619)None during JSON deserialization instead of
panicking. (#607)borsh to version 1.1 as a result of
a security advisory. (#621)Thank you to @gai6948 for their contribution! Also thank you to all of those that pushed for the security advisory changes.
Fixes an issue with is_integer returning incorrect results for mantissa's 10^n where n >=
Fixes an issue with trunc_with_scale implicitly rounding in some scenarios
trunc_with_scale implicitly rounding in some
scenarios (#600)Thank you to @mkatychev for your contribution this release.
As the minor releases for Rust Decimal are getting smaller, I'll be looking at formally starting version 2 of the Decimal library. This will be unstab
As the minor releases for Rust Decimal are getting smaller, I'll be looking at formally starting version 2 of the Decimal library. This will be unstable as we find experiment with a new API and address some of the constraints the current implementation of the library has (e.g. revised error types for better const support).
proptest feature support for Decimal (#582).is_integer function for an efficient means to check whether a Decimal is an integer with no
fractional portion. (#591).Thank you to @cardoe for your contribution!
Fixes an issue with checked_cos and checked_sin where QUARTER_PI would send the calculation into an infinite loop.
checked_cos and checked_sin where QUARTER_PI would send the calculation into an infinite
loop. (#585)New trunc_with_scale function which allows you to truncate a decimal number whilst retaining a specified precision. (#576),
trunc_with_scale function which allows you to truncate a decimal number whilst retaining a specified
precision. (#576), (#578)Decimal
number to enter into an invalid state. (#575)There were also a couple of housekeeping tasks, to help pave the way for v2 of Rust Decimal.
cargo.toml and leverage the new dep: syntax where
required. (#579)Thank you @c410-f3r and @jon-chuang for your contributions to this release!
Bumped borsh and criterion dependencies to the latest versions.
borsh and criterion dependencies to the latest
versions. (#568)serde-with-str
feature. (#571)Thanks @attila-lin for your help bumping dependencies.
Implement TryFrom<&str> for Decimal
TryFrom<&str> for Decimal (#560)Option<Decimal> when
using serde-with-str (#565)rescale preventing Decimal::ZERO to be rescaled to an invalid
precision (#566)Thank you to @c410-f3r for your diligent help adding features to this library!
Added Copy/Clone traits for rkvy::Archive
Copy/Clone traits for rkvy::Archive (#539)cargo-edit instructions (#538)deserialize_any except in explicit use
cases (#558)This release wouldn't have been possible without the help of the community. Special call out and thank you to @icy-ux, @CAD97, @nicksenger, @c410-f3r and @yongqli.
Fixes docs.rs failing to compile due to mutually exclusive diesel1 and diesel2 features. The previous compile_error! was in fact an anti-pattern. Cons
docs.rs failing to compile due to mutually
exclusive diesel1 and diesel2 features. The previous compile_error!
was in fact an anti-pattern.
Consequently,
if both diesel1 and diesel2 features are specified then it will favor diesel2. This helps prevent any conflict
scenarios
and ultimately resolves the downstream docs.rs issue.serde-with-* features now support Option variants (#524).
serde-with-* features now support Option<T> variants (#524).core::iter::Product (#525).2.0.0-rc.1 support via db-diesel2-mysql and db-diesel2-postgres
features. (#533
and (#532)).from_str when parsing Decimal::MAX with a fractional
portion. (#530).Thank you to @Guara92 who made the initial diesel2 PR which made parallel implementation
a breeze! Also, once again, thank you
to @c410-f3r for implementing the missing Product trait!
Expands rand support to implement SampleUniform to allow for rng.gen_range calls
rand support to implement SampleUniform to allow for rng.gen_range
calls (#519)rkyv framework support for zero-cost (de)
serialization (#520)A big thank you to @lukesneeringer and @dovahcrow for your help building features for this release.
Introduces new feature rand which allows for random number generation within rust_decimal (#517).
rand which allows for random number generation
within rust_decimal (#517).A big thank you to @c410-f3r for their contributions to this release!
Fixes issue with no_std compatability introduced in 1.23.0 (#501).
Fixes issue with no_std compatability introduced
in 1.23.0 (#501).
Add BorschSchema support for the borsh feature (#498).
BorschSchema support for the borsh feature (#498).TryFrom for Decimal primitive types (#493).to_i64 to support i64::MIN (#496).Inv from num_traits (#495).Thank you @turion, @arthurprs and @jnitard for your help with this release.
Add support for borsh serialization/deserialization (#478).
Saturating op variants have been added: saturating_add, saturating_sub and saturating_mul
Additional fuzz testing for deserialize
from_str is now over 4x faster, utilizing const generics and
TCO (#456)from_str issue with rounding issues when too many digits in source
string. (#453)serde-with functionality for greater configurability when
using serde (#459)This is truly a collaborative release and has some significant contributions from the community. A huge thank you to everyone involved:
This is a minor dot release and contains library updates (#334) and expanded scope in prelude to include num_traits::Signed (#450). While subtle, it a
This is a minor dot release and contains library updates (#334) and
expanded scope in prelude to include num_traits::Signed (#450).
While subtle, it also expands the way towards some bigger improvements including variable precision.
Of a larger note, the minimum Rust compiler version has been updated so we can start utilizing various compiler features
(such as const generics). The miminum compiler version is now 1.51.0.
Thank you to @c410-f3r and @jracollins for your contributions to this release.
Fixes integer handling for to_f64 when scale is set to 0. #443. Thank you @anatols for creating this fix.
to_f64 when scale is set
to 0. #443.
Thank you @anatols for creating this fix.rocket-traits. #445.
Thank you @Misterio77 for putting this together.db-diesel-mysq. #446.Binds deserialize so that invalid scale values cannot be set. This may be a breaking change for some users leveraging this in a const function. #428.
deserialize so that invalid scale values cannot be set. This may be a breaking change for some users
leveraging
this in a const function. #428.round_sf whereby integral values that started with a 0 or 1 would output incorrect rounded
numbers. #430, #437.from_f32_retain and from_f64_retain functions which allow parsing a floating point number and retaining any
excess precision. #438.Implement sin/cos/tan functions which are enabled within the maths feature. #413.
sin/cos/tan functions which are enabled within the maths
feature. #413.round_sf and round_sf_with_strategy to enable significant figure
rounding. #421std feature from arrayvec usage #417.Thank you to @c410-f3r for all your help with fuzz and benchmarking improvements!
A minor bug and feature release which adds a couple of new functions as well as cleans up some documentation:
A minor bug and feature release which adds a couple of new functions as well as cleans up some documentation:
serde-arbitrary-precision feature.
#402.
Thanks @JamesHinshelwood!
for finding and fixing this!log10 support to the maths feature. Please note that ln and log10 will now panic on invalid input since
both
functions have a checked_* equivalent. This is the preferred approach going forward, however if you would like to
re-enable
the previous behavior please use the maths-nopanic
feature. #397.Decimal library including TWO, TEN, ONE_HUNDRED, ONE_THOUSAND,
and NEGATIVE_ONE.
#400.-0 whereby - would be
output #406. Thanks
@edwardycl!to_f64. #401.BUILD.md file to help people get set up with Rust Decimal locally and cleaned up some
documentation examples.Fixes an issue #398 where Decimal::ZERO.ln() would panic rather than returning Decimal::ZERO. This aligns the behavior with calling ln on negative dec
Fixes an issue #398 where Decimal::ZERO.ln() would panic rather
than returning Decimal::ZERO. This
aligns the behavior with calling ln on negative decimals.
Thank you to @SebRollen for finding and fixing this.
Fixes an overflow issue during division under some specific circumstances.
Fixes an overflow issue during division under some specific circumstances. (#392)
A bug fix release following on from 1.14.0:
A bug fix release following on from 1.14.0:
Decimal a negating overflow would occur during
underflow.
#384. Thank you to @c410-f3r for
finding
this as part of fuzz testing.exp whereby negative values lost accuracy due to inability to converge.
#378. Thank you to @schungx for
finding this and proposing a fix.Added checked_exp and checked_norm_pdf functions #375.
checked_exp and checked_norm_pdf functions #375.Thank you to @falsetru, @schungx and @blasrodri for your help with this release!
This is a minor update to the library providing a few new features and one breaking change (I'm not using semver properly here sorry).
This is a minor update to the library providing a few new features and one breaking change (I'm not using semver properly here sorry).
#[must_use] added to functions to provide additional compiler hints.try_from_i128_with_scale function added to safely handle i128 overflow errors.c-repr feature added which will ensure that #[repr(C)] is used on the Decimal type.
Thanks @jean-airoldie.from_scientific. It now supports a wider range of values as well has slightly faster
performance.pow functions. This is breaking since powi(u64) has been renamed
to powi(i64). If you want to
continue using u64 arguments then please use powu(u64). The fractional functions should be considered experimental
for the time being
and may have subtle issues that still need ironing out. Functions are now:
powi, checked_powi - When the exponent is a signed integer.powu, checked_powu - When the exponent is an unsigned integer.powf, checked_powf - When the exponent is a floating point number. Please note, numbers with a fractional
component
will use an approximation function.powd, checked_powd - When the exponent is a Decimal. Please note, numbers with a fractional component will
use
an approximation function.Adds num_traits::One back to rust_decimal::prelude to prevent unnecessary downstream dependency breakages. Thanks @spearman.
Adds num_traits::One back to rust_decimal::prelude to prevent unnecessary downstream dependency breakages.
Thanks @spearman.
Fixes an issue #361 when rounding a small number towards zero.
Fixes an issue #361 when rounding a small number towards zero.
Fixes small regression whereby 0 - 0 was producing -0. Thank you @KonishchevDmitry for providing a swift fix (#356).
Fixes small regression whereby 0 - 0 was producing -0. Thank
you @KonishchevDmitry for
providing a swift fix (#356).
Added num_traits::Zero back to rust_decimal::prelude to prevent unnecessary downstream dependency breakages.
Added num_traits::Zero back to rust_decimal::prelude to prevent unnecessary downstream dependency breakages.
Consequently, parsing -0 etc _in general_ will automatically be parsed as 0. Of course, this _may_ be a breaking change so if this functionality is re…
This version releases faster operation support for add, sub, cmp, rem and mul to match the renewed div
strategy.
It does this by leveraging 64 bit support when it makes sense, while attempting to still keep 32 bit optimizations in
place.
To ensure correct functionality, thousands more tests were included to cover a wide variety of different scenarios
and bit combinations. Compared to previous operations, we get the following speed improvements:
add - up to 2.2x fasterdiv - up to 428x fastermul - up to 1.8x fasterrem - up to 1.08x fastersub - up to 2.5x fasterOf course, if old functionality is desired, it can be re-enabled by using the legacy-ops feature.
Other improvements include:
String allocation when parsing a scientific number format.
Thanks @thomcc for the fix #350.sqrt when using the smallest possible representable
number. #349.maths feature. Future work will involve speeding up this feature by keeping
operations
in an internal format until required.MIN, MAX and ZERO. Deprecated min_value() and max_value() in favor of these
new
constants.-0 now gets corrected to 0. During operation rewrite I needed to consider operations such as -0 * 2 - in cases
like
this I opted towards 0 always being the right number and -0 being superfluous (since +0 == -0). Consequently,
parsing
-0 etc in general will automatically be parsed as 0. Of course, this may be a breaking change so if this
functionality is required then please create an issue with the use case described.is_negative to negative in UnpackedDecimal.This is a documentation only release and has no new functionality included. Thank you @c410-f3r for the documentation fix.
This is a documentation only release and has no new functionality included. Thank you @c410-f3r for the documentation fix.
This release includes a number of bug fixes and ergonomic improvements.
This release includes a number of bug fixes and ergonomic improvements.
log and pow are not required (e.g. simple financial applications). Mathematical functionality is now behind
the maths
feature flag. #321.u128 and i128 parsing. #332Checked* traits from num_traits. #333. Thank you
@teoxoychecked_powi function to maths feature. #336from_parts to avoid accidental scale clobbering. #337Arbitrary trait for rust-fuzz support. This is behind the feature flag rust-fuzz.
#338e^-1 returning an incorrect approximation. #339RoundingStrategy naming and documentation (#340).
The old naming was ambiguous in interpretation - the new naming
convention follows guidance from other libraries to ensure an easy to follow scheme. The RoundingStrategy enum now
includes:
MidpointNearestEven (previously BankersRounding)MidpointAwayFromZero (previously RoundHalfUp)MidpointTowardZero (previously RoundHalfDown)ToZero (previously RoundDown)AwayFromZero (previously RoundUp)ToNegativeInfinity - new rounding strategyToPositiveInfinity - new rounding strategymantissa directly. #341rust_decimal_macros to make re-exporting the macro from a downstream crate more approachable.
Enabling the reexportable feature will ensure that the generated code doesn't require rust_decimal to be exposed
at
the root level. #343Fixes bug in bincode serialization where a negative symbol causes a buffer overflow (#317).
Fixes a bug introduced in division whereby certain values when using a large remainder cause an incorrect results (
Fixes bug introduced in neg whereby sign would always be turned negative as opposed to being correctly negated.
neg whereby sign would always be turned negative as opposed to being correctly negated.Thank you KonishchevDmitry for finding and fixing this.
Upgrade postgres to 0.19 and tokio-postgres to 0.7.
postgres to 0.19 and tokio-postgres to 0.7.serde serialization by preventing heap allocation.legacy-ops. Further work to improve other operations will
be made available in future versions.TryFrom for f32/f64 to/from DecimalThank you for the the community help and support for making this release happen, in particular: jean-airoldie, gakonst, okaneco and c410-f3r.
Added arbitrary precision support for serde_json deserialization
serde_json deserialization (#283)u128 and i128 FromPrimitive overrides to prevent default implementation kicking in. Also adds default From
interceptors to avoid having to use trait directly. (#282)serde-bincode as serde-str to make usage clearer (#279)UpperExp and LowerExp traits. (#271)tokio-postgres and postgres libraries.powi, sqrt, exp, norm_cdf, norm_pdf, ln & erf (#281, #287)sum across immutable references (#280)Thank you for all the community help and support with this release, in particular xilec, remkade and Anders429.
Make std support the default to prevent breaking downstream library dependencies. To enable no_std support please set default features to false and op
Make std support the default to prevent breaking downstream library dependencies. To enable no_std support please
set
default features to false and opt-in to any required components. e.g.
rust_decimal = { default-features = false, version = "1.8.0" }
no_std support added to Rust Decimal by default. std isn't required to use Rust Decimal, however can be enabled by using the std feature. #190
no_std support added to Rust Decimal by default. std isn't required to use Rust Decimal, however can be enabled by
using the std feature. #190to_f64. #267.Clone, Copy, PartialEq and Eq derives to RoundingStrategy.Enables bincode support via the feature serde-bincode. This provides a long term fix for a regression that was introduced in version 0.6.5 (tests now
bincode support via the feature serde-bincode. This provides a long term fix for a regression
that was introduced in version 0.6.5 (tests now cover this
case!). Issue 43.rescale on zero would not have an affect. This was due to an early exit condition which failed to
set the new scale. Issue 253.min and max functions, similar to what f32 and f64 provide. Thank
you @michalsieron.is_sign_positive and is_sign_negative to specify that the sign bit is being checked.Please note: feature naming conventions have been modified, however backwards compatible aliases have been created where necessary. It's highly recommended that you move over to the new naming conventions as these aliases may be removed at a later date.
Your coding agent can read these notes before it upgrades. Set up the MCP server →