Skip to main content

u256_to_price

Function u256_to_price 

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

Convert a U256 amount to [Price].

  • If decimals == 18, the value represents wei and uses the dedicated lossless Price::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 [PRICE_RAW_MAX].