I would like to divide a Balance
into two parts. One is 10% of value
and another part is 90% of the value
. BalanceOf<T>
is the Balance
of a pallet.
type Balance: AtLeast32BitUnsigned
+ FullCodec
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ Default
+ scale_info::TypeInfo
+ MaxEncodedLen;
let value: BalanceOf<T> = some_balance;
let deposit: BalanceOf<T> = 0.1 * value;
let actual: BalanceOf<T> = value - deposit;
The error message is the following.
cannot multiply `{float}` by `<<T as pallet::Config>::Currencies as orml_traits::MultiCurrency<<T as frame_system::Config>::AccountId>>::Balance`
the trait `Mul<<<T as pallet::Config>::Currencies as orml_traits::MultiCurrency<<T as frame_system::Config>::AccountId>>::Balance>` is not implemented for `{float}`
Another approach is to use sp_runtime::traits::CheckedDiv
let value: BalanceOf<T> = some_balance;
let deposit = value
.checked_div(&10u128.into())
.ok_or(DispatchError::Other("Arithmetic error"))?;
let actual = value - deposit;
There I get this error.
the trait `From<u128>` is not implemented for `<<T as pallet::Config>::Currencies as orml_traits::MultiCurrency<<T as frame_system::Config>::AccountId>>::Balance`
What is the best possible way to approach this safely?