How can I multiply a uint by a decimal fraction integer? This is what I have so far - I am explicitly converting the decimal fraction integer to type uint. Will this have unintended consequences?

uint gasPriceInWei = tx.gasprice * 1000000000;
uint percentOfGasPrice = uint(transactionCostInWei) * uint(.1);
  • 2
    If it's always 0.1, just divide by 10.
    – user19510
    Jan 15, 2018 at 1:19

1 Answer 1


The proper way to do this in solidity would be to divide by 10:

uint percentOfGasPrice = uint(transactionCostInWei)/10;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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