Mike Gershman
SCJP 1.4, SCWCD in process
Originally posted by Joyce Lee:
How about this?
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Mike Gershman
SCJP 1.4, SCWCD in process
Originally posted by Peter Chase:
No, that's not a good way to do it. The reason is that floating-point arithmetic ("double" is a floating-point type) is not exact. So you're quite likely to end up printing something like 10.020000000000001 or 10.0199999999999 .
Mike Gershman
SCJP 1.4, SCWCD in process
Originally posted by Joyce Lee:
Peter, I printed the output using the Math.round approach. But it didn't end up printing like 10.020000000000001 or 10.0199999999999. I may have missed out something. Could you give a value that would end up something like that? Thanks.
Originally posted by David Dickinson:
Layne,
Indeed your right I have always set my Delta (the allowable difference between the two numbers under evaluation) to 0 to ensure accuracy. But this would be the simplest way of doing things.
That old saying "I can't see for things for looking at them" springs to mind
Thank you!
Originally posted by Joyce Lee:
I still don't get the idea why using Math.round approach would end up 10.020000000000001 or 10.0199999999999. I did a quick search in this forum. Here are the threads that recommended using Math.round approach to round off to 2 decimal places. Did I miss out anything?
Thread 1
Thread 2
Thread 3
Thread 4
Thread 5
Originally posted by Layne Lund:
The problem isn't with Math.round(); it's with doing arithmetic on the result that is returned from this method!