In my node, Balance type is u128. I have following variable

let per_block = 100_000_000_000_000_000_u128;
let total = 50_000_000_000_000_000_000_000_u128;
let ratio = per_block.checked_div(total);

let user_a = 10_000_000_000_000_000_000_000_u128 * ratio;

But ratio is 0 even in above case. How do I perform such calculation to get user_a finally?

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3d556bfb809632b885bf008680dfec8e

1 Answer 1


Check out the per_things.

You could use Perquintill here:

use sp_runtime::Perquintill;

let ratio = Perquintill::from_rational(per_block, total);
let user_a = 10_000_000_000_000_000_000_000_u128 * ratio;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.