From 856e75d2d911dfe5b249f6473234de190452ed98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 10 May 2018 07:37:18 +0900 Subject: [PATCH] Add: NumberUtil - numberWithCommas --- src/game/lib/number_util.js | 7 +++++++ test/number_util.html | 16 ++++++++++++++++ test/test_number_util.js | 6 ++++++ 3 files changed, 29 insertions(+) create mode 100644 src/game/lib/number_util.js create mode 100644 test/number_util.html create mode 100644 test/test_number_util.js 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