decimal-rs
High precision decimal with maximum precision of 38.
Feature Flags
serde
: When this optional dependency is enabled,Decimal
implements theserde::Serialize
andserde::Deserialize
traits.
Usage
To build a decimal, use Decimal
:
use Decimal;
let n1: Decimal = "123".parse.unwrap;
let n2: Decimal = "456".parse.unwrap;
let result = n1 + n2;
assert_eq!;
To build a decimal from Rust primitive types:
use Decimal;
let n1 = from;
let n2 = from;
let result = n1 + n2;
assert_eq!;
Decimal supports high precision arithmetic operations.
use Decimal;
let n1: Decimal = "123456789.987654321".parse.unwrap;
let n2: Decimal = "987654321.123456789".parse.unwrap;
let result = n1 * n2;
assert_eq!;
Decimal can be encoded to bytes and decoded from bytes.
use Decimal;
let n1 = "123456789.987654321"..unwrap;
let mut bytes = Vec new;
n1.encode.unwrap;
let n2 = decode;
assert_eq!;
Rust Version
This version of decimal-rs
requires Rust 1.51 or later.
License
This project is licensed under the Apache-2.0 license (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in decimal-rs
by you, shall be licensed as Apache-2.0, without any additional
terms or conditions.