0 votes
1 view
in Blockchain by (12.8k points)

I have written this simple solidity code to calculate some numbers. But, ethereum blockchain gives different outputs on each function. Is there anything wrong on my code or it's ethereum blockchain issue?

My solidity code:

pragma solidity ^0.4.24;

contract Calculate {

    uint balance = 50000000000000000000;

    function done() public pure returns (uint) {

        return (50000000000000000000 / 3000) * 3000;


    function fail() public view returns (uint) {

        return (balance / 3000) * 3000;




done() function returns 50000000000000000000

fail() function returns 49999999999999998000

1 Answer

0 votes
by (29.8k points)

 The issue is in the 'done case', the compiler doesn't actually emit code to do the calculation. The calculation is instead done at compile time, and a single constant is put in its place.

The compiler, unlike the EVM at runtime, does support decimal math.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !