summaryrefslogtreecommitdiffstatshomepage
path: root/py/formatfloat.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/formatfloat.c')
-rw-r--r--py/formatfloat.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/py/formatfloat.c b/py/formatfloat.c
index 60dcee6f54..dc7fc1d1fd 100644
--- a/py/formatfloat.c
+++ b/py/formatfloat.c
@@ -330,7 +330,11 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
// Print the digits of the mantissa
for (int i = 0; i < num_digits; ++i, --dec) {
int32_t d = (int32_t)f;
- *s++ = '0' + d;
+ if (d < 0) {
+ *s++ = '0';
+ } else {
+ *s++ = '0' + d;
+ }
if (dec == 0 && prec > 0) {
*s++ = '.';
}