| Crates.io | rust_decimal_ext |
| lib.rs | rust_decimal_ext |
| version | 1.36.1 |
| created_at | 2024-11-27 13:02:39.725875+00 |
| updated_at | 2024-11-28 08:00:57.390303+00 |
| description | Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations. |
| homepage | |
| repository | https://github.com/86maid/rust-decimal-ext |
| max_upload_size | |
| id | 1462997 |
| size | 739,821 |
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.
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;