diff --git a/platform/source/minimal-printf/mbed_printf_implementation.c b/platform/source/minimal-printf/mbed_printf_implementation.c index 5d2a8288deb..df403653512 100644 --- a/platform/source/minimal-printf/mbed_printf_implementation.c +++ b/platform/source/minimal-printf/mbed_printf_implementation.c @@ -302,6 +302,8 @@ static void mbed_minimal_formatted_string_double(char *buffer, size_t length, in precision *= 10; } + value = (value - integer) * precision; + /* convert to positive number */ if (value < 0.0) { value *= -1.0; @@ -313,7 +315,8 @@ static void mbed_minimal_formatted_string_double(char *buffer, size_t length, in value -= decimal; if (!((value > -0.5) && (value < 0.5))) { - decimal++; + if (decimal + 1 < precision) + decimal++; } /* write decimal part */