diff --git a/libs/libc/stdio/lib_dtoa_engine.c b/libs/libc/stdio/lib_dtoa_engine.c index f9abd97936d..f508bb2a2d1 100644 --- a/libs/libc/stdio/lib_dtoa_engine.c +++ b/libs/libc/stdio/lib_dtoa_engine.c @@ -127,12 +127,13 @@ int __dtoa_engine(double x, FAR struct dtoa_s *dtoa, int max_digits, /* If limiting decimals, then limit the max digits to no more than the * number of digits left of the decimal plus the number of digits right - * of the decimal + * of the decimal. If the integer value is 0, there are only values to + * the right of the decimal point in dtoa->digits. */ if (max_decimals != 0) { - max_digits = MIN(max_digits, max_decimals + MAX(exp + 1, 1)); + max_digits = MIN(max_digits, max_decimals + MAX(exp + 1, 0)); } /* Round nearest by adding 1/2 of the last digit before converting to