Don't display trailing '.' in _dcvt

In the two helper functions that _dcvt calls for 'f' and 'e' mode, if
there are no digits to display after the decimal point, don't add one.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2019-12-17 22:00:49 -08:00 committed by Ken Brown
parent d7e4cdb291
commit a8b5de7ff5
1 changed files with 12 additions and 3 deletions

View File

@ -93,6 +93,7 @@ print_f (struct _reent *ptr,
{ {
if (p == start) if (p == start)
*buf++ = '0'; *buf++ = '0';
if (decpt < 0 && ndigit > 0)
*buf++ = '.'; *buf++ = '.';
while (decpt < 0 && ndigit > 0) while (decpt < 0 && ndigit > 0)
{ {
@ -148,11 +149,15 @@ print_e (struct _reent *ptr,
} }
*buf++ = *p++; *buf++ = *p++;
if (dot || ndigit != 0) if (ndigit > 0)
*buf++ = '.'; dot = 1;
while (*p && ndigit > 0) while (*p && ndigit > 0)
{ {
if (dot) {
*buf++ = '.';
dot = 0;
}
*buf++ = *p++; *buf++ = *p++;
ndigit--; ndigit--;
} }
@ -168,6 +173,10 @@ print_e (struct _reent *ptr,
{ {
while (ndigit > 0) while (ndigit > 0)
{ {
if (dot) {
*buf++ = '.';
dot = 0;
}
*buf++ = '0'; *buf++ = '0';
ndigit--; ndigit--;
} }