In my dApp the user sets the entry fee for the game they are creating. The entry fee for games will usually be between $5 USD and $50 USD. What unit should I use for the contract method that accepts payment for the game (i.e. - the type to preface the relevant method parameter with)? Should I use: wei, gwei, eth, etc.?

Also, what Solidity type should I use internally in my contract that does a fair number of numeric calculations when it comes time to pay the players? I assume a fixed point type like uint* is not a good fit? I'm asking this question both for storage and memory variables.

I assume for percentages I can just use uint and divide by 100 internally? But I'm asking the above questions for parameters that will be receiving floating point numbers generally.

  • 2
    It's reasonable to use a fixed number of decimals (like 10^18 wei being 1 ether), or you can use an explicit rational number with a separate numerator and denominator (e.g. (7, 100) means 0.07). The latter is the approach taken here: programtheblockchain.com/posts/2018/02/27/…. – user19510 Jun 21 '18 at 20:07
  • 1
    For your first question, you probably want to accept an amount in wei, and the appropriate type for the parameter is uint256. – user19510 Jun 21 '18 at 20:08
  • @smarx Thanks. Now all I have to do is find a reliable API to give me a quote in USD for Eth, and another one to convert between one fiat currency and another so I can show the user a friendly monetary value. – Robert Oschler Jun 21 '18 at 20:19

Solidity does not support floating point variables because they are harder to be deterministic with and are not the most secure. The most common version of decimals is to have a uint that is not a single ETH or USD, but 1/10^18th of one.


You may use ABDK Math 64.64 library. It operates with binary fixed point numbers (64 binary digits after dot) and contains all basic math operations. It uses int128 type to represent fixed point number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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