8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ae94cf2 commit 1e162d3Copy full SHA for 1e162d3
Python/bltinmodule.c
@@ -1488,14 +1488,22 @@ builtin_round(self, args)
1488
if (!PyArg_ParseTuple(args, "d|i:round", &x, &ndigits))
1489
return NULL;
1490
f = 1.0;
1491
- for (i = ndigits; --i >= 0; )
+ i = abs(ndigits);
1492
+ while (--i >= 0)
1493
f = f*10.0;
- for (i = ndigits; ++i <= 0; )
1494
- f = f*0.1;
+ if (ndigits < 0)
1495
+ x /= f;
1496
+ else
1497
+ x *= f;
1498
if (x >= 0.0)
- return PyFloat_FromDouble(floor(x*f + 0.5) / f);
1499
+ x = floor(x + 0.5);
1500
1501
+ x = ceil(x - 0.5);
1502
1503
1504
else
- return PyFloat_FromDouble(ceil(x*f - 0.5) / f);
1505
1506
+ return PyFloat_FromDouble(x);
1507
}
1508
1509
static PyObject *
0 commit comments