Solidity:
version=soljson-v0.4.18+commit.9cf6e910.js
version=soljson-v0.4.17+commit.bdeb9e52.js
The code responsible for error is:
uint256 public result = (50000e18*2500)/300;
The error received is:
Error: Type rational_const 1250000000000000000000000/3 is not implicitly convertible to expected type uint256. Try converting to type ufixed256x53 or use an explicit conversion.
An explicit conversion to uint256 tells Not yet implemented - FixedPointType.
Currently, all constants are considered of ufixed datatype. To enable division of constants, one of them must be uint256. One way to do that is as follows:
uint256 val = 3/uint256(2)
Numbers actually have an internal type of "RationalNumber" which is attempted to be converted into either an integer (<= 256 bits) or a fixed point type. Your example number can only be converted into a fixed point type as it is not an integer and since fixed point types are not fully supported yet it will fail.
Can you please explain your suggestion? What I understand is you would want the compiler to do truncated division without any warning?
Thanks for this useful information. This issue was not a suggestion, but more like a question. I expected those numbers to be able to be int and be able to be converted to uint256 implicitly. However, I still have a doubt:
Your example number can only be converted into a fixed point type as it is not an integer
Is 50000e18*2500 not a integer? I believed integers can range till 2**256
What will be the result of int/int?
The expression (50000e18*2500)/300 is evaluated and considered as a single number, which is 1250000000000000000000000/3.
See http://solidity.readthedocs.io/en/develop/types.html#rational-and-integer-literals
What data type should be used to store the result? I was unable to find a datatype to store the result. Following data types did not work:
fixed public result1 = 1250000000000000000000000/3; //same as previous error
ufixed128x19 public result2 = 1250000000000000000000000/3; //same as previous error
ufixed256x53 public result = 1250000000000000000000000/3; //UnimplementedFeatureError: Not yet implemented - FixedPointType.
The support for fixed point types is incomplete. You will not be able to store this result in any type currently.
If you are certain you need this number, consider doing fixed point types by hand, but it is very likely that you could avoid it by restructuring your code.
Yes! Till then I can use a workaround by making one of the numbers as uint256 and then perform the division.
uint256 public result = 1250000000000000000000000/uint256(3);
Most helpful comment
Yes! Till then I can use a workaround by making one of the numbers as
uint256and then perform the division.uint256 public result = 1250000000000000000000000/uint256(3);