Add: NumberUtil - numberWithCommas
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
class NumberUtil {
|
||||||
|
|
||||||
|
static numberWithCommas(x) {
|
||||||
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
@@ -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");
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user