SQLite Forum

change in round() function
Login
Ooopsie ... missed something in that round code -- it should only use that if the rounding difference is exactly 0.5 -- Should be:

```
double roundhalfeven(double x, int digits)
{
   double scale = pow(10.0, digits);
   double y;
   x *= scale;
   y = round(x);
   if (fabs(x - y) == 0.5)
      y = 2.0 * round(x / 2.0);
   return y / scale;
}
```

or even simpler

```
double roundhalfeven(double x, int digits)
{
   double scale = pow(10.0, digits);
   x *= scale;
   return (x - remainder(x, 1.0)) / scale;
}
```