1 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
2 #include <msvcrt/stdlib.h>
3 #include <msvcrt/stdio.h>
4 #include <msvcrt/string.h>
10 _gcvt (double value, int ndigits, char *buf)
14 sprintf (buf, "%-#.*g", ndigits, value);
16 /* It seems they expect us to return .XXXX instead of 0.XXXX */
19 if (*p == '0' && p[1] == '.')
20 memmove (p, p + 1, strlen (p + 1) + 1);
22 /* They want Xe-YY, not X.e-YY, and XXXX instead of XXXX. */
23 p = strchr (buf, 'e');
26 p = buf + strlen (buf);
27 /* They don't want trailing zeroes. */
28 while (p[-1] == '0' && p > buf + 2)
31 if (p > buf && p[-1] == '.')
32 memmove (p - 1, p, strlen (p) + 1);