### annoying rounding problems...

i have made a program and its output is sometimes something like `1.0000005` . that's pretty annoying but i can get it solved with some rounding. but when my answer should be `1.3333333` for example i also get the precision problem and i get like `1.333333339` . i can't use a simple round to solve this so could anyone tell me how to get the right value?
I don't think there's an easy answer. But judging by the examples quoted, your results have limited precision. I'd recommend using double or long double, which should be better than float. But that merely pushes the problem further along into the later digits.
Last edited on
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
Please read this. There is no easy solution to your problem. You can use less precision (print less digits after period) so `1.333333339` will become `1.333333`

EDIT: sin(1.0) is equal sin(1.0)? Do you really think so?
http://ideone.com/MY6EYc
Last edited on
hmm ok thank you
Topic archived. No new replies allowed.