summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a5ffcea)
raw | patch | inline | side by side (parent: a5ffcea)
author | Florian Forster <octo@noris.net> | |
Wed, 22 Dec 2010 18:03:31 +0000 (19:03 +0100) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 22 Dec 2010 18:03:31 +0000 (19:03 +0100) |
share/collection.js | patch | blob | history |
diff --git a/share/collection.js b/share/collection.js
index 6aff20fb41d4883b00d366b5de64574a89bd005e..1a62f6e34e64a11d53b8771b027ce0f36fdaf6b4 100644 (file)
--- a/share/collection.js
+++ b/share/collection.js
function value_to_string (value) /* {{{ */
{
- var abs_value = Math.abs (value);
+ var abs_value;
+ var v2s = function (value)
+ {
+ var tmp = Math.round (100.0 * value) / 100.0;
+ return ("" + tmp);
+ }
+
+ if (value == null)
+ return ('NaN');
+ else if (value == 0)
+ return ('0');
+
+ abs_value = Math.abs (value);
if ((abs_value < 10000) && (abs_value >= 0.1))
- return ("" + value);
+ return (v2s (value));
else if (abs_value > 1)
{
if (abs_value < 10000000)
- return ("" + (value / 1000) + "k");
+ return (v2s (value / 1000) + "k");
else if (abs_value < 10000000000)
- return ("" + (value / 1000000) + "M");
+ return (v2s (value / 1000000) + "M");
else if (abs_value < 10000000000000)
- return ("" + (value / 1000000000) + "G");
+ return (v2s (value / 1000000000) + "G");
else
- return ("" + (value / 1000000000000) + "T");
+ return (v2s (value / 1000000000000) + "T");
}
else
{
if (abs_value >= 0.001)
- return ("" + (value * 1000) + "m");
+ return (v2s (value * 1000) + "m");
else if (abs_value >= 0.000001)
- return ("" + (value * 1000000) + "u");
+ return (v2s (value * 1000000) + "u");
else
- return ("" + (value * 1000000000) + "n");
+ return (v2s (value * 1000000000) + "n");
}
} /* }}} function value_to_string */