2022-08-23 22:09:08 +00:00
|
|
|
import { BigNumber } from './bignumber';
|
2022-08-30 08:21:27 +00:00
|
|
|
import { formatNumber } from './format-number';
|
2022-08-23 22:09:08 +00:00
|
|
|
|
|
|
|
describe('formatNumber and formatNumberPercentage', () => {
|
|
|
|
it.each([
|
2022-11-22 18:14:16 +00:00
|
|
|
{ v: new BigNumber(123), d: 3, o: '123.00' },
|
2022-08-23 22:09:08 +00:00
|
|
|
{ v: new BigNumber(123.123), d: 3, o: '123.123' },
|
2022-11-22 18:14:16 +00:00
|
|
|
{ v: new BigNumber(123.123), d: 6, o: '123.123' },
|
2022-08-23 22:09:08 +00:00
|
|
|
{ v: new BigNumber(123.123), d: 0, o: '123' },
|
|
|
|
{ v: new BigNumber(123), d: undefined, o: '123.00' }, // it default to 2 decimal places
|
2022-08-30 08:21:27 +00:00
|
|
|
{ v: new BigNumber(30000), d: undefined, o: '30,000.00' },
|
|
|
|
{ v: new BigNumber(3.000001), d: undefined, o: '3.000001' },
|
2022-09-14 09:05:26 +00:00
|
|
|
])(`formats given number with decimals correctly`, ({ v, d, o }) => {
|
2022-08-23 22:09:08 +00:00
|
|
|
expect(formatNumber(v, d)).toStrictEqual(o);
|
|
|
|
});
|
|
|
|
});
|