Skip to content

Commit 30e2f1b

Browse files
committed
helpers/format-num: Simplify implementation using Intl.NumberFormat
1 parent 2683404 commit 30e2f1b

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

app/helpers/format-num.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
import { helper } from '@ember/component/helper';
22

3-
export function formatNum(value) {
4-
if (value === 0) {
5-
return '0';
6-
}
3+
const numberFormat = new Intl.NumberFormat('en');
74

8-
let ret = '';
9-
let cnt = 0;
10-
while (value > 0) {
11-
if (cnt > 0 && cnt % 3 === 0) {
12-
ret = `,${ret}`;
13-
cnt = 0;
14-
}
15-
ret = (value % 10) + ret;
16-
cnt += 1;
17-
value = Math.floor(value / 10);
18-
}
19-
return ret;
5+
export function formatNum(value) {
6+
return numberFormat.format(value);
207
}
218

229
export default helper(params => formatNum(params[0]));

0 commit comments

Comments
 (0)