1 QUnit.test("kivi.format_amount function German number style with thousand separator", function( assert ) {
2 kivi.setup_formats({ numbers: '1.000,00' });
4 assert.equal(kivi.format_amount('1e1', 2), '10,00', 'format 1e1');
5 assert.equal(kivi.format_amount(1000, 2), '1.000,00', 'format 1000');
6 assert.equal(kivi.format_amount(1000.1234, 2), '1.000,12', 'format 1000.1234');
7 assert.equal(kivi.format_amount(1000000000.1234, 2), '1.000.000.000,12', 'format 1000000000.1234');
8 assert.equal(kivi.format_amount(-1000000000.1234, 2), '-1.000.000.000,12', 'format -1000000000.1234');
11 QUnit.test("kivi.format_amount function German number style without thousand separator", function( assert ) {
12 kivi.setup_formats({ numbers: '1000,00' });
14 assert.equal(kivi.format_amount('1e1', 2), '10,00', 'format 1e1');
15 assert.equal(kivi.format_amount(1000, 2), '1000,00', 'format 1000');
16 assert.equal(kivi.format_amount(1000.1234, 2), '1000,12', 'format 1000.1234');
17 assert.equal(kivi.format_amount(1000000000.1234, 2), '1000000000,12', 'format 1000000000.1234');
18 assert.equal(kivi.format_amount(-1000000000.1234, 2), '-1000000000,12', 'format -1000000000.1234');
21 QUnit.test("kivi.format_amount function English number style with thousand separator", function( assert ) {
22 kivi.setup_formats({ numbers: '1,000.00' });
24 assert.equal(kivi.format_amount('1e1', 2), '10.00', 'format 1e1');
25 assert.equal(kivi.format_amount(1000, 2), '1,000.00', 'format 1000');
26 assert.equal(kivi.format_amount(1000.1234, 2), '1,000.12', 'format 1000.1234');
27 assert.equal(kivi.format_amount(1000000000.1234, 2), '1,000,000,000.12', 'format 1000000000.1234');
28 assert.equal(kivi.format_amount(-1000000000.1234, 2), '-1,000,000,000.12', 'format -1000000000.1234');
31 QUnit.test("kivi.format_amount function English number style without thousand separator", function( assert ) {
32 kivi.setup_formats({ numbers: '1000.00' });
34 assert.equal(kivi.format_amount('1e1', 2), '10.00', 'format 1e1');
35 assert.equal(kivi.format_amount(1000, 2), '1000.00', 'format 1000');
36 assert.equal(kivi.format_amount(1000.1234, 2), '1000.12', 'format 1000.1234');
37 assert.equal(kivi.format_amount(1000000000.1234, 2), '1000000000.12', 'format 1000000000.1234');
38 assert.equal(kivi.format_amount(-1000000000.1234, 2), '-1000000000.12', 'format -1000000000.1234');
41 QUnit.test("kivi.format_amount function negative places", function( assert ) {
42 kivi.setup_formats({ numbers: '1000.00' });
44 assert.equal(kivi.format_amount(1.00045, -2), '1.00045', 'negative places');
45 assert.equal(kivi.format_amount(1.00045, -5), '1.00045', 'negative places 2');
46 assert.equal(kivi.format_amount(1, -2), '1.00', 'negative places 3');
49 QUnit.test("kivi.format_amount function bugs and edge cases", function( assert ) {
50 kivi.setup_formats({ numbers: '1.000,00' });
52 assert.equal(kivi.format_amount(0.00005), '0,00005', 'messing with small numbers and no precision');
53 assert.equal(kivi.format_amount(undefined), '0', 'undefined');
54 assert.equal(kivi.format_amount(''), '0', 'empty string');
55 assert.equal(kivi.format_amount(undefined, 2), '0,00', 'undefined with precision');
56 assert.equal(kivi.format_amount('', 2), '0,00', 'empty string with prcesion');
58 assert.equal(kivi.format_amount(0.545, 0), '1', 'rounding up with precision 0');
59 assert.equal(kivi.format_amount(-0.545, 0), '-1', 'neg rounding up with precision 0');
61 assert.equal(kivi.format_amount(1.00), '1', 'autotrim to 0 places');
63 assert.equal(kivi.format_amount(10), '10', 'autotrim does not harm integers');
64 assert.equal(kivi.format_amount(10, 2), '10,00' , 'autotrim does not harm integers 2');
65 assert.equal(kivi.format_amount(10, -2), '10,00' , 'autotrim does not harm integers 3');
66 assert.equal(kivi.format_amount(10, 0), '10', 'autotrim does not harm integers 4');
68 assert.equal(kivi.format_amount(0, 0), '0' , 'trivial zero');