Sorry for not being specific, I just thought the context isn’t important.
Anyway the question can be seen as an extension of my other question on Progressbars in win32 should I put the whole code here or the link is enough ?
The problem in its simplest form can be described as :
double d1 = x.xxxxxx;
double d2 = x.xxxxxx;
double d3 = x.xxxxxx;
double d4 = x.xxxxxx;
double d5 = x.xxxxxx;
...
...
double dn = x.xxxxxx;
int i1 = (int)d1;
int i2 = (int)d2;
int i3 = (int)d3;
int i4 = (int)d4;
int i5 = (int)d5;
...
...
int in = (int)dn;
int i = i1+i2+i3+i4+i5+...+in;
double d = d1+d2+d3+d4+d5+...+in;
now i needs to be not less then d - 0.5;
How to do that ?
EDIT : Code modified.
EDIT 2 : The number of n can not be predicted, and it is possible that d1,d2,…,dn are less then 1, something like, 0.345627.
I think what you are interested in is error diffusion:
Each time you round the value, you see how much error is introduced, and propagate a correction to the next calculation. This way, your error can never build up.