#big-decimal #convert #ethers #u256 #allowing #interop

bigdecimal-ethers-ext

Library allowing conversion between BigDecimal and ethers

3 unstable releases

0.2.1 Sep 14, 2023
0.2.0 Jul 25, 2023
0.1.0 Jul 18, 2023

#3 in #u256

Download history 12/week @ 2024-02-05 46/week @ 2024-02-19 4/week @ 2024-02-26 8/week @ 2024-03-04 14/week @ 2024-03-11 14/week @ 2024-03-18 1/week @ 2024-03-25 83/week @ 2024-04-01

113 downloads per month

MIT license

26KB
307 lines

bigdecimal-ethers-ext

BigDecimal interoperability with ethers-rs types.

Example

let big_decimal = BigDecimal::from_f64(10.5).unwrap();
// Convert to an u256 with 18 decimals.
let u256 = big_decimal.to_ethers_u256(18).unwrap();
println!("{u256}");
// 10500000000000000000
// Convert from an u256 with 18 decimals to a BigDecimal.
let to_big_decimal = BigDecimal::from_ethers_u256(&u256, 18).unwrap();
println!("{to_big_decimal}");
// 10.500000000000000000

Dependencies

~26–44MB
~809K SLoC