Originally Posted by
Ngoo Jia Xun
Use ceil and float to round up?
Code:
lround((double)cents/(double)x);
Where "cents" is the monetary value and x is an integer divisor. If x is a float, you do not need to cast it to a double. Otherwise, both those casts are necessary -- and, nb, do not do this:
Code:
lround((double)(cents/x));
Originally Posted by
nonoob
This does not sound like a cumulative rounding error but instead the programmer elected to use floating point constant when there was no use of floating point warranted. An integer divide-by-10 would do the job. And I bet those Patriot Missile programmers get paid more than I do.
Implying somebody (perhaps) got thru school without having this point brought home properly. Hopefully we saved some lives here today .
I always feel overzealous about this one, lol (thanks CornedBee & mike65535).