What's the correct way to multiply a number in ray (1e27) with a number in wad (1e18) to get the result in wad? E.g., I have an interest rate [ray] and a balance [wad] that I am multiplying to get a balance [wad].

I'm using DS-Math

uint256 amount = wmul(balances[owner], rate);

I'm seeing the result come out to 1000000000000000000000000000000 (1e27 / ray)

Should I just divide by 1e9 or is there a better, out-of-the-box way?

  • You have to divide by 1 ray = 1e27.
    – Ismael
    Apr 8 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.