Skip to main content
3 of 3
Add formatting for future viewers
Shane Fontaine
  • 18.3k
  • 20
  • 56
  • 83

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