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

1 Answer 1


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 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.