pub fn u256_to_price(amount: U256, decimals: u8) -> Result<Price>Expand description
Convert a U256 amount to [Price].
- If
decimals == 18the value represents wei and we leverage the dedicatedQuantity::from_weiconstructor for loss-less conversion. - For other precisions we fall back to a floating-point conversion identical
to the pre-existing path in
convert_u256_to_f64and then construct aQuantitywith the smallerdecimals(clamped toFIXED_PRECISION).
ยงErrors
Returns an error when the helper must fall back to the floating-point path
(i.e. decimals != 18) and the provided amount cannot be converted to an
f64 (see convert_u256_to_f64).