i am writing a function to convert fractions to intgers for example:
.636 -> 636 or .45 -> 45
int ret_int(double input)
{
while(true)
{
// this line is for debugging only
cout << input << " " << floor(input) << endl;
if(input == floor(input)) return input;
input = input * 10;
}
}
for some inputs it is working fine for example:
But for some inputs :
which i cant understand the floor and the input are the same so why the function does not return
some inputs also do this:
floor(23450) = 23499
weird?
if anybody has another approach (another method) to do the job i would be thankful