S
Shea Martin
Any one have a better/simpler method for rounding a float to the nearest
1/10th? This is currently what I am using, and there must be a better
way, or perhaps a canned method that I am not aware of.
double z = atof(arg[1]);
z = z*100.0;
int zi = (int)floor((double)z);
int ri = zi%10;
zi -= ri;
zi += ( ri < 5 ) ? 0 : 10;
z = (double)zi/(double)100;
NOTE: originally the doubles were floats, but 1.5*100 = 149.9999 when
using floats, correct answer given when doubles used.
Any suggestions would be great thank.
~S
1/10th? This is currently what I am using, and there must be a better
way, or perhaps a canned method that I am not aware of.
double z = atof(arg[1]);
z = z*100.0;
int zi = (int)floor((double)z);
int ri = zi%10;
zi -= ri;
zi += ( ri < 5 ) ? 0 : 10;
z = (double)zi/(double)100;
NOTE: originally the doubles were floats, but 1.5*100 = 149.9999 when
using floats, correct answer given when doubles used.
Any suggestions would be great thank.
~S