Function fixed_to_i128

Source
fn fixed_to_i128<T>(x: &T) -> Option<i128>
where T: FixedPointNumber, T::Inner: TryInto<i128> + Copy,
Expand description

Extracts the exact integer value of a fixed-point number as i128, returning None if the value has a non-zero fractional component.

A fixed-point number represents inner / DIV. This function returns inner / DIV only when inner is exactly divisible by DIV - i.e. when the fixed-point value is a whole number with no fractional part.

§Arguments

  • x - The fixed-point number to inspect.

§Returns

  • Some(n) if x represents the exact integer n
  • None if x has a fractional component, or if internal conversion fails

§Examples

let x = FixedU64::saturating_from_integer(5);
assert_eq!(fixed_to_i128(&x), Some(5));

let x = FixedU64::saturating_from_rational(3, 2); // 1.5
assert_eq!(fixed_to_i128(&x), None);