Skip to content

Commit 3c4c069

Browse files
committed
py/formatfloat: Workaround (fix?) incorrect rounding for %f format.
1 parent b64e057 commit 3c4c069

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

py/formatfloat.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
308308
}
309309

310310
// Round
311-
if (f >= FPCONST(5.0)) {
311+
// If we print non-exponential format (i.e. 'f'), but a digit we're going
312+
// to round by (e) is too far away, then there's nothing to round.
313+
if ((org_fmt != 'f' || e <= 1) && f >= FPCONST(5.0)) {
312314
char *rs = s;
313315
rs--;
314316
while (1) {

0 commit comments

Comments
 (0)