divideByThousand

说明

将数字按千位分隔

源码

用法

divideByThousand.test.ts
1
import { divideByThousand } from "../../utility/number/divideByThousand";
2
3
4
describe('divideByThousand tests...', () => {
5
6
test('method divideByThousand should return the correct value', () => {
7
const received: number[] = [
8
// 小于千位的数字
9
11, 45, -56, 0,
10
// 刚好等于千位的数字
11
110, -323,
12
// 大于千位的数字
13
1100, 3456687, -4534236423642364,
14
];
15
const expected = [
16
'11', '45', '-56', '0',
17
'110', '-323',
18
'1,100', '3,456,687', '-4,534,236,423,642,364'
19
];
20
21
received.forEach((v, i) => {
22
const result = divideByThousand(v);
23
24
expect(result).toBe(expected[i]);
25
});
26
});
27
28
test('method divideByThousand should use customized separator that passed', () => {
29
const received = [
30
{
31
num: 12345,
32
separator: '_',
33
},
34
];
35
const expected = ['12_345'];
36
37
received.forEach((v, i) => {
38
const result = divideByThousand(v.num, v.separator);
39
40
expect(result).toBe(expected[i]);
41
});
42
});
43
44
})
Copied!
最近更新 1yr ago
复制链接