rust_decimal_ext

Crates.iorust_decimal_ext
lib.rsrust_decimal_ext
version1.36.1
created_at2024-11-27 13:02:39.725875+00
updated_at2024-11-28 08:00:57.390303+00
descriptionDecimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
homepage
repositoryhttps://github.com/86maid/rust-decimal-ext
max_upload_size
id1462997
size739,821
(86maid)

documentation

https://docs.rs/rust_decimal_ext/

README

rust_decimal_ext   Latest Version Docs Badge

rust_decimal_ext is an extension library that adds more operator trait support to rust_decimal. With this library, you can conveniently perform a variety of arithmetic operations, such as addition, subtraction, multiplication, and division, on Decimal types. It also supports automatic conversion and operations with numbers, strings, and other types.

Usage

use rust_decimal_ext::prelude::*;

let mut a: Decimal = Decimal::from(1) + 1;
let mut b = Decimal::from(1) + 2.5;
let mut c = Decimal::from(10) + "5.5";

a += 1;
b += 2.5;
c += "5.5";

assert!(a == 3);
assert!(b == 6);
assert!(c == "21");

assert!(a > 2);
assert!(b < 10);
assert!(c >= "20");
assert!(c <= "21");

a.partial_cmp(&10).unwrap();
a.partial_cmp(&10.0).unwrap();
a.partial_cmp("10").unwrap();

// painc
_ = Decimal::from(1) + f64::NAN;
_ = Decimal::from(1) + f64::INFINITY;
_ = Decimal::from(1) + f64::NEG_INFINITY;
Commit count: 982

cargo fmt