Skip to main content

u256_to_quantity

Function u256_to_quantity 

Source
pub fn u256_to_quantity(amount: U256, decimals: u8) -> Result<Quantity>
Expand description

Convert a U256 amount to [Quantity].

  • If decimals == 18, the value represents wei and uses the dedicated lossless Quantity::from_wei constructor.
  • Other precisions use checked integer scaling and clamp decimals to [FIXED_PRECISION]. Discarded source digits are rounded half to even.

ยงErrors

Returns an error if scaling overflows or the result exceeds [QUANTITY_RAW_MAX].