2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 09:24:04 +00:00
books/tests/test_utils.js

35 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-07-14 16:12:34 +00:00
const numberFormat = require('frappejs/utils/numberFormat');
const assert = require('assert');
describe('Number Formatting', () => {
2018-02-21 09:43:21 +00:00
it('should format numbers', () => {
2018-07-14 16:12:34 +00:00
assert.equal(numberFormat.formatNumber(100), '100.00');
assert.equal(numberFormat.formatNumber(1000), '1,000.00');
assert.equal(numberFormat.formatNumber(10000), '10,000.00');
assert.equal(numberFormat.formatNumber(100000), '100,000.00');
assert.equal(numberFormat.formatNumber(1000000), '1,000,000.00');
assert.equal(numberFormat.formatNumber(100.1234), '100.12');
assert.equal(numberFormat.formatNumber(1000.1234), '1,000.12');
2018-02-21 09:43:21 +00:00
});
2018-02-21 09:43:21 +00:00
it('should parse numbers', () => {
2018-07-14 16:12:34 +00:00
assert.equal(numberFormat.parseNumber('100.00'), 100);
assert.equal(numberFormat.parseNumber('1,000.00'), 1000);
assert.equal(numberFormat.parseNumber('10,000.00'), 10000);
assert.equal(numberFormat.parseNumber('100,000.00'), 100000);
assert.equal(numberFormat.parseNumber('1,000,000.00'), 1000000);
assert.equal(numberFormat.parseNumber('100.1234'), 100.1234);
assert.equal(numberFormat.parseNumber('1,000.1234'), 1000.1234);
2018-02-21 09:43:21 +00:00
});
2018-02-21 09:43:21 +00:00
it('should format lakhs and crores', () => {
2018-07-14 16:12:34 +00:00
assert.equal(numberFormat.formatNumber(100, '#,##,###.##'), '100.00');
assert.equal(numberFormat.formatNumber(1000, '#,##,###.##'), '1,000.00');
assert.equal(numberFormat.formatNumber(10000, '#,##,###.##'), '10,000.00');
assert.equal(numberFormat.formatNumber(100000, '#,##,###.##'), '1,00,000.00');
assert.equal(numberFormat.formatNumber(1000000, '#,##,###.##'), '10,00,000.00');
assert.equal(numberFormat.formatNumber(10000000, '#,##,###.##'), '1,00,00,000.00');
assert.equal(numberFormat.formatNumber(100.1234, '#,##,###.##'), '100.12');
assert.equal(numberFormat.formatNumber(1000.1234, '#,##,###.##'), '1,000.12');
2018-02-21 09:43:21 +00:00
});
});