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>
7 _gcvt (double value, int ndigits, char *buf)
11 sprintf (buf, "%-#.*g", ndigits, value);
13 /* It seems they expect us to return .XXXX instead of 0.XXXX */
16 if (*p == '0' && p[1] == '.')
17 memmove (p, p + 1, strlen (p + 1) + 1);
19 /* They want Xe-YY, not X.e-YY, and XXXX instead of XXXX. */
20 p = strchr (buf, 'e');
23 p = buf + strlen (buf);
24 /* They don't want trailing zeroes. */
25 while (p[-1] == '0' && p > buf + 2)
28 if (p > buf && p[-1] == '.')
29 memmove (p - 1, p, strlen (p) + 1);