diff --git a/src/game/lib/number_util.js b/src/game/lib/number_util.js new file mode 100644 index 0000000..48a56c8 --- /dev/null +++ b/src/game/lib/number_util.js @@ -0,0 +1,7 @@ +class NumberUtil { + + static numberWithCommas(x) { + return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); + } + +} \ No newline at end of file diff --git a/test/number_util.html b/test/number_util.html new file mode 100644 index 0000000..2b7eba8 --- /dev/null +++ b/test/number_util.html @@ -0,0 +1,16 @@ + + + + + + QUnit Example + + + +
+
+ + + + + \ No newline at end of file diff --git a/test/test_number_util.js b/test/test_number_util.js new file mode 100644 index 0000000..bdd4766 --- /dev/null +++ b/test/test_number_util.js @@ -0,0 +1,6 @@ +QUnit.test( "NumberWithCommas", function( assert ) { + assert.equal(NumberUtil.numberWithCommas(1), "1", "NumberWithCommas"); + assert.equal(NumberUtil.numberWithCommas(1000), "1,000", "NumberWithCommas"); + assert.equal(NumberUtil.numberWithCommas(100000), "100,000", "NumberWithCommas"); + assert.equal(NumberUtil.numberWithCommas(1000000), "1,000,000", "NumberWithCommas"); +}); \ No newline at end of file