hello, for one of my programs I need to acquire the decimal off of a number, for example, if a double has value of "123.45" I need an int to have the value "45".
to do this, I have the following code
double value, tempValue;
int decimalValue;
value = 123.45
tempValue = value - floor(value);
while(tempValue != floor(tempValue)
{
tempValue *= 10;
}
decimalValue = tempValue;
it does what it's supposed to, but for some reason doesn't get out of the loop when it should, here's the output of this loop:
"
tempValue: .45
floor(tempValue): 0
tempValue: 4.5
floor(tempValue): 4
tempValue: 45
floor(tempValue): 45
tempValue: 450
floor(tempValue): 450
etc..
"
it does this until tempValue = 4.5 x 10^15, then it breaks the loop. The only thing I can think of that would cause this is the fact that tempValue is a double, for example, it may say "45" on cout, but actually may hold the value of "45.00000000001"? any suggestions?
~J