]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/string.qh
Reimplement ftos_mindecimals in a simpler and more correct way
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / string.qh
index bd0c8d30f8a97bef964e41990628003627390dda..384188091d0c4b0c92917bacafd3253707be3fe6 100644 (file)
@@ -16,7 +16,6 @@
        }
 #endif
 
-// TODO: macro
 string seconds_tostring(float sec)
 {
        float minutes = floor(sec / 60);
@@ -282,16 +281,24 @@ void buf_save(float buf, string pFilename)
 
 /**
  * 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)
 {
        // inhibit stupid negative zero
        if (number == 0) number = 0;
-       // we have sprintf...
        return sprintf("%.*f", decimals, number);
 }
 
+/**
+ * converts a number to a string with the minimum number of decimals
+ */
+string ftos_mindecimals(float number)
+{
+       // inhibit stupid negative zero
+       if (number == 0) number = 0;
+       return sprintf("%.7g", number);
+}
+
 int vercmp_recursive(string v1, string v2)
 {
        int dot1 = strstrofs(v1, ".", 0);