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

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

Ex:

Commission = 5%

Sales = 100 ETH

100 x 5% (0.05) = 5 ETH

and in soliditySolidity:

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?

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?

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?

edited title
Link
bbusdriver
  • 1.2k
  • 2
  • 18
  • 33

TypeError: Operator * not compatible with types assign decimal to a variable in solidity

Source Link
bbusdriver
  • 1.2k
  • 2
  • 18
  • 33

TypeError: Operator * not compatible with types

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?