Suppose i have a contract with decimals and total Supply as follow. How can i check if tokenAmountInWei pass in is integer value in form of ether.

decimals = 18
totalSupply = 1000000

function someFunction(uint tokenAmountInWei) {
    // check if tokenAmountInWei convert to ether is integer value
}
up vote 6 down vote accepted

This should work:

pragma solidity ^0.4.24;

contract Test {

    function checkIntegerETH(uint a) public pure returns (bool) {
        return (a % 1 ether == 0);
    }
}

Here we are basically confirming that a has no remainder when being divided by 1018 (1 ether).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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