[Ethereum] How should I multiply ether by a decimal

solidity

I'd like to multiply Ether by a decimal (a proportion, e.g. 0.05). I've got:

ufixed proportion; // What type should proportion be?

function functionName() {
  var Ether = msg.value; // (in units of wei)
  var proportionOfEther = Ether * proportion
  ...

My Solidity linter is saying that * is not compatible with uint256 (the Ether) and ufixed128x128 (the proportion).

Best Answer

Instead of multiplying by a decimal, multiply and divide by integers.

i.e. (Ether * 5)/100

Related Topic