Fix gcvt to always show 'ndigits' of precision
Leading zeros after the decimal point should not count towards the 'ndigits' limit. This makes gcvt match glibc and the posix gcvt man page. Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
233c16aa61
commit
d7e4cdb291
|
@ -349,15 +349,10 @@ _gcvt (struct _reent *ptr,
|
||||||
char *end;
|
char *end;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (invalue < 1.0)
|
/* We always want ndigits of precision, even if that means printing
|
||||||
{
|
* a bunch of leading zeros for numbers < 1.0
|
||||||
/* what we want is ndigits after the point */
|
*/
|
||||||
p = _dtoa_r (ptr, invalue, 3, ndigit, &decpt, &sign, &end);
|
p = _dtoa_r (ptr, invalue, 2, ndigit, &decpt, &sign, &end);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p = _dtoa_r (ptr, invalue, 2, ndigit, &decpt, &sign, &end);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (decpt == 9999)
|
if (decpt == 9999)
|
||||||
{
|
{
|
||||||
|
@ -383,11 +378,12 @@ _gcvt (struct _reent *ptr,
|
||||||
if (buf == save)
|
if (buf == save)
|
||||||
*buf++ = '0';
|
*buf++ = '0';
|
||||||
*buf++ = '.';
|
*buf++ = '.';
|
||||||
while (decpt < 0 && ndigit > 0)
|
|
||||||
|
/* Leading zeros don't count towards 'ndigit' */
|
||||||
|
while (decpt < 0)
|
||||||
{
|
{
|
||||||
*buf++ = '0';
|
*buf++ = '0';
|
||||||
decpt++;
|
decpt++;
|
||||||
ndigit--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print rest of stuff */
|
/* Print rest of stuff */
|
||||||
|
|
Loading…
Reference in New Issue