The function getInt() is always returning more than 1. Shouldn't it do a round off for values less than 0.5 and return 0 ? Please check the imagetest function and let me know, if I am doing something incorrectly or if there is a way out.

1 Answer 1


When I try to run this code on remix it gave UnimplementedFeatureError: Not yet implemented - FixedPointType. Which you can see here This is not possible to use uint(3/30) as you are doing. Casting of any floating point using uint is not acceptable.

The Fixed Point are not yet unuseable in solidity as it documentation says:

Fixed point numbers are not fully supported by Solidity yet. They can be declared, but cannot be assigned to or from.

You may solve this problem by.

1)You may use divi function from ABDK Math 64.64 library. It divides one integer by another and returns the result as 64.64-bit fixed point number.

2)You can multiply the number by 10^n. Where 'n' is number of decimals in your return value.



I want to understand - why does my test1 function doesn't return 0 but returns 1

Well the uint shouldn't return anything at all instead it must give an error as mentioned above.

  • 1
    Haseeb, You mention - 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 : But that's not correct. Also, i want to understand - why does my test1 function not return 0 but returns 1.
    – rajatBlock
    Jun 13, 2020 at 12:31
  • @rajatBlock hope you like my answer Jun 13, 2020 at 13:01
  • 1
    Thanks.I suppose there is an issue with REMIX - it allowed me to deploy the contract with the compilation warning. And, also what it does is - gives the last correct answer before the number became floating point. Anyways, all this aside - I think still point no. 2 in your "You may solve this problem by section." still does not help me deal with the actual problem - which is how to return 0 for numbers less than 0.5. Rather the answer from your edit - that it gives the compilation error, is correct and cannot be actually deployed.
    – rajatBlock
    Jun 13, 2020 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.