1

How can I calculate percentage of a number in solidity? say I want to calculate 95% of the number 200.

How should I go about doing that ?

0

1 Answer 1

0

It is hard to calculate exact number by division in computer.

If just you want to get 95% of 200, 200/100 * 95 is the answer. But if you ask how can i get exact number of result of division, it can't in some number.

6
  • 3
    isn't it (200 * 95) / 100 ?
    – Adrin
    Jul 10, 2020 at 4:42
  • MATH :) hint it's the same
    – pasevin
    Jul 10, 2021 at 9:09
  • 1
    @pasevin not the same in solidity
    – Richard
    Aug 4, 2021 at 7:23
  • @Richard Why do you say so? ``` function test1() public pure returns(uint) { return (200 * 95) / 100; } function test2() public pure returns(uint) { return 200 / 100 * 95; } ``` Will return exactly the same result.
    – pasevin
    Aug 6, 2021 at 7:26
  • 1
    Good point, thanks for clarifying.
    – pasevin
    Aug 7, 2021 at 9:05

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