Im trying to find a cheap solution in Solidity where a uint256 type caluclation for 1000-1001 results 0. I know that i run into overflow problems here and cant use Safemath.

1 Answer 1


What about this?

pragma solidity 0.4.25;

contract Subtract {

    function subtract(uint a, uint b) public pure returns(uint remainder) {
        if(b>a) return 0;
        return b-a;

Hope it helps.


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.