Hello i use the following in order to truncate a double value (found somewhere and modified :) ) However you must be careful in here, because there could be an overflow in double fac = Num/Seed
#include <math.h>
#include <stdio.h>
double truncate(double Num, double Seed)
{
// get rational factor
double fac = Num / Seed;
// get natural factor
fac = (fac < 0) ? (ceil(fac)) : (floor(fac));
// fac = (fac < 0) ? static\_cast<int>(fac-0.5) : static\_cast<int>(fac+0.5);
// return multiple
return fac \* Seed;
}
int main()
{
double val = 4./3.;
printf("%6.4f\\n",truncate(val,1e-04));
return 0;
}