Fix M_Ftrim

- Use '%f' instead of '%g' to avoid going scientific. Should also fix some
  compiler warnings.
- The trailing zero trimming code is now useful. It started on the terminating
  byte before and wouldn't have done anything with '%g' anyway.
- Use the absolute fractional value to avoid a sign.
This commit is contained in:
James R 2020-02-17 19:38:14 -08:00
parent 9bd9e667c5
commit e3ba369ae4
1 changed files with 7 additions and 6 deletions

View File

@ -2618,14 +2618,15 @@ const char * M_Ftrim (double f)
static char dig[9];/* "0." + 6 digits (6 is printf's default) */
int i;
/* I know I said it's the default, but just in case... */
sprintf(dig, "%.6g", modf(f, &f));
if (dig[0])
sprintf(dig, "%.6f", fabs(modf(f, &f)));
/* trim trailing zeroes */
for (i = strlen(dig)-1; dig[i] == '0'; --i)
;
if (dig[i] == '.')/* :NOTHING: */
return "";
else
{
for (i = strlen(dig); dig[i] == '0'; --i)
;
dig[i + 1] = '\0';
return &dig[1];/* skip the 0 */
}
else
return "";
}