1

According to readthedocs.io:

"Division on integer literals used to truncate in earlier versions, but it will now convert into a rational number, i.e. 5 / 2 is not equal to 2, but to 2.5".

Yet, when I try simple math problems like this on Remix, they are truncated.
So, "5 / 2" still equals 2, and I have to use "%" or "remainder = _dividend - (quotient * _divisor)" to produce the remainder separately.

I believe I am using the latest compiler version "0.4.24". So is the information from readthedocs just wrong? Or does it means something else?

CreatedAMadman
  • 190
  • 1
  • 14

1 Answers1

4

I believe what that note is saying is that this function:

function test() public pure returns (uint256) {
    return (5 / 2) * 10;
}

used to return 20 but now returns 25.

There are no fixed-point/floating-point numbers in Solidity, so you can't return a number like 2.5, but you can use one up until the point where you try to store it in an integer.

user19510
  • 27,999
  • 2
  • 30
  • 48