option to write floats as ints when possible

omit the ".0" in values like "3.0"
This commit is contained in:
ac-stef
2015-05-18 14:59:41 +02:00
parent e5fc8b35a2
commit c4e1155dcc
3 changed files with 14 additions and 15 deletions
+10 -9
View File
@@ -491,19 +491,20 @@ void intret(int v)
commandret = newstring(t);
}
const char *floatstr(float v)
const char *floatstr(float v, bool neat)
{
static int n = 0;
static string t[3];
n = (n + 1)%3;
ftoa(t[n], v);
return t[n];
static string s;
static int i = 0;
if(i > MAXSTRLEN - 100) i = 0;
char *t = s + i;
snprintf(t, 90, !neat && (v) == int(v) ? "%.1f" : "%.7g", v); // was ftoa()
i += strlen(t) + 1;
return t;
}
void floatret(float v)
void floatret(float v, bool neat)
{
commandret = newstring(floatstr(v));
commandret = newstring(floatstr(v, neat));
}
void result(const char *s) { commandret = newstring(s); }