If I correctly understood your question, I am afraid it does not have a complete solution. Since a float is stored with a finite number of bits, not all fractions can be represented, especially the ones that are not decimal numbers like 2/3
. Even for decimal numbers, not all of them can be represented.
In other words, your method will never be called by the float representation of 2/3
as an input, since this representation does not exist. You might be called with 0.66666666
(with whatever the limit of digits would be in Java), but that is not 2/3
...
See this link for more details about floating point representation in Java: http://introcs.cs.princeton.edu/java/91float/