Possible Duplicate:
Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?
sqrt(25.0)
turns out to be 4.99999 ,instead of 5
how would I fix this problem?
Possible Duplicate:
Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?
sqrt(25.0)
turns out to be 4.99999 ,instead of 5
how would I fix this problem?
As Jack said, you can't avoid this. However, a 'fix' might be to round the sqrt result. For example using the round function.
Since you can't avoid it, take a look at rounding functions, such as: round() , ceil() , floor()
There's also this nice article about it.