float median(float a, float b, float c);
// converts a number to a string with the indicated number of decimals
-// works for up to 10 decimals!
string ftos_decimals(float number, float decimals);
+string ftos_mindecimals(float number);
bool fexists(string f);
/**
* converts a number to a string with the indicated number of decimals
- * works for up to 10 decimals!
*/
string ftos_decimals(float number, int decimals)
{
return sprintf("%.*f", decimals, number);
}
+// strips trailing 0s from a float number, e.g. 1.200000 -> 1.2
+string ftos_mindecimals(float number)
+{
+ string s = ftos(number);
+ int k = strstrofs(s, ".", 0);
+ if(k >= 0)
+ {
+ int i = strlen(s);
+ while(substring(s, i - 1, 1) == "0") i--;
+ s = substring(s, 0, i);
+ }
+ return s;
+}
+
int vercmp_recursive(string v1, string v2)
{
int dot1 = strstrofs(v1, ".", 0);
return;
if(me.checked)
- cvar_set(me.cvarName, ftos(me.yesValue));
+ cvar_set(me.cvarName, ftos_mindecimals(me.yesValue));
else
- cvar_set(me.cvarName, ftos(me.noValue));
+ cvar_set(me.cvarName, ftos_mindecimals(me.noValue));
CheckSendCvars(me, me.cvarName);
}
if (!me.cvarName)
return;
- cvar_set(me.cvarName, ftos(me.value));
+ cvar_set(me.cvarName, ftos_mindecimals(me.value));
CheckSendCvars(me, me.cvarName);
}