Function unsigned_fixed_to_decimal

Source
pub fn unsigned_fixed_to_decimal(num: u128, decimals: u8) -> Option<Decimal>
Expand description

Convert unsigned fixed-point number to [Decimal].

Returns None if it cannot be represented as a [Decimal].

ยงExamples

use gmsol::utils::unsigned_fixed_to_decimal;
use rust_decimal_macros::dec;

assert_eq!(
    unsigned_fixed_to_decimal(100_451_723_195, 6),
    Some(dec!(100_451.723195)),
);

assert_eq!(
    unsigned_fixed_to_decimal(u128::MAX, 10),
    None,
);