Permalink
Browse files

Comma-ify pretty printed numbers

  • Loading branch information...
1 parent aef1e86 commit f90d2172fcce28456333acbba3dc18ffd691e1fb @tibbe committed Jan 1, 2012
Showing with 15 additions and 2 deletions.
  1. +1 −1 HISTORY.md
  2. +14 −1 assets/monitor.js
View
@@ -1,4 +1,4 @@
-## 0.3.0.0 (2011-12-31)
+## 0.3.0.0 (2012-01-01)
* Add gauges and change counters to always be monotonically increasing
View
@@ -2,6 +2,19 @@ $(document).ready(function () {
"use strict";
// Number formatters
+ function commaify(n)
+ {
+ var nStr = n.toString();
+ var x = nStr.split('.');
+ var x1 = x[0];
+ var x2 = x.length > 1 ? '.' + x[1] : '';
+ var rgx = /(\d+)(\d{3})/;
+ while (rgx.test(x1)) {
+ x1 = x1.replace(rgx, '$1' + ',' + '$2');
+ }
+ return x1 + x2;
+ }
+
function formatSuffix(val, opt_prec) {
if (val === null) {
return "N/A";
@@ -223,7 +236,7 @@ $(document).ready(function () {
});
}
if (!paused)
- elem.text(value);
+ elem.text(commaify(value));
});
}

0 comments on commit f90d217

Please sign in to comment.