Skip to main content
2 of 3
edited title
bbusdriver
  • 1.2k
  • 2
  • 18
  • 33

assign decimal to a variable in solidity

I'm trying to calculate commission, but having a hard time doing a very easy math in solidity.

Ex:

Commission = 5%

Sales = 100 ETH

100 x 5% (0.05) = 5 ETH

and in solidity:

uint sales = 100;
uint afterCommission = sales * 0.05;

When I do this, I get

TypeError: Operator * not compatible with types uint256 and rational_const 1/2

Solidity can't assign a decimal points to a variable? How can I make this work?

bbusdriver
  • 1.2k
  • 2
  • 18
  • 33