hardStudy question · answer published in Blockchain interview questions, so no pointssolidityarithmetic
Price that comes out as zero
This function returns 0 for amount = 5. Why, and what is the fix?
// price has 2 decimals: 1 unit = 100
function cost(uint256 amount) public pure returns (uint256) {
return amount / 10 * 100;
}Discussion 0
Join free to post in the discussion.
Related questions
- storage, memory, calldataBlockchain Developer
- Why emit eventsBlockchain Developer
- What msg.sender isBlockchain Developer
- Wei and etherBlockchain Developer
- view vs pureBlockchain Developer
- Sending ETH to a functionBlockchain Developer
- receive vs fallbackBlockchain Developer
- Reading a missing mapping keyBlockchain Developer