Add: NumberUtil - numberWithCommas

This commit is contained in:
2018-05-10 07:37:18 +09:00
parent ca4847a397
commit 856e75d2d9
3 changed files with 29 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
class NumberUtil {
static numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.6.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.6.0.js"></script>
<script src="../src/game/lib/number_util.js"></script>
<script src="test_number_util.js"></script>
</body>
</html>
+6
View File
@@ -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");
});