J
jacob navia
Richard said:That, at least, is true. The best solution is to understand the inherent
limitations in representing fractions, and to recognise that the
appropriate way to deal with this is to deal with the rounding at the
display stage.
That wasn't what the OP asked. He wanted to round it without any
display, maybe to be used in further calculation or whatever.
And it IS possible to round correctly a double precision
number. One of the possible solutions is:
#include <stdio.h>
#include <math.h>
void RoundMyDouble (long double *value, short numberOfPrecisions)
{
long double fv=fabsl(*value);
if (fv > 1e17)
return ;
long long p = powl(10.0L, numberOfPrecisions);
*value = (long long)(*value * p + 0.5L) / (double)p;
}
This is quite awful, but it works (with 64 bit long long and
wider precision long double)
Ah, we're back to "nonsense" as your synonym for "correct solution that
Jacob Navia doesn't understand", are we?
Nonse means to tell the OP that what he is asking is
impossible!
I think is the pompous tone that makes me nervous.
"Ex cathedra"...