Function cfg_primitives::conversion::convert_balance_decimals
source · pub fn convert_balance_decimals<Precision: AtLeast32BitUnsigned + TryInto<usize>, Balance: BaseArithmetic + Copy>(
from: Precision,
to: Precision,
balance: Balance
) -> Result<Balance, ArithmeticError>
Expand description
Converts a uint
Balance
of one precision into a Balance
of another
precision i.e:
use cfg_primitives::conversion::convert_balance_decimals;
assert_ok!(convert_balance_decimals(3u32, 6u32, 1_234_567u64), 1_234_567_000u64);
assert_ok!(convert_balance_decimals(6u32, 3u32, 1_234_567u64), 1_234u64);
assert_ok!(convert_balance_decimals(6u32, 6u32, 1_234_567u64), 1_234_567u64);
assert_err!(convert_balance_decimals(6u32, 42u32, 1_000_000u64), ArithmeticError::Overflow);