forked from d3/d3-format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-type-f-test.js
52 lines (46 loc) · 1.99 KB
/
format-type-f-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var tape = require("tape"),
format = require("../");
tape("format(\"f\") can output fixed-point notation", function(test) {
test.equal(format.format(".1f")(0.49), "0.5");
test.equal(format.format(".2f")(0.449), "0.45");
test.equal(format.format(".3f")(0.4449), "0.445");
test.equal(format.format(".5f")(0.444449), "0.44445");
test.equal(format.format(".1f")(100), "100.0");
test.equal(format.format(".2f")(100), "100.00");
test.equal(format.format(".3f")(100), "100.000");
test.equal(format.format(".5f")(100), "100.00000");
test.end();
});
tape("format(\"+$,f\") can output a currency with comma-grouping and sign", function(test) {
var f = format.format("+$,.2f");
test.equal(f(0), "+$0.00");
test.equal(f(0.429), "+$0.43");
test.equal(f(-0.429), "-$0.43");
test.equal(f(-1), "-$1.00");
test.equal(f(1e4), "+$10,000.00");
test.end();
});
tape("format(\",.f\") can group thousands, space fill, and round to significant digits", function(test) {
test.equal(format.format("10,.1f")(123456.49), " 123,456.5");
test.equal(format.format("10,.2f")(1234567.449), "1,234,567.45");
test.equal(format.format("10,.3f")(12345678.4449), "12,345,678.445");
test.equal(format.format("10,.5f")(123456789.444449), "123,456,789.44445");
test.equal(format.format("10,.1f")(123456), " 123,456.0");
test.equal(format.format("10,.2f")(1234567), "1,234,567.00");
test.equal(format.format("10,.3f")(12345678), "12,345,678.000");
test.equal(format.format("10,.5f")(123456789), "123,456,789.00000");
test.end();
});
tape("format(\"f\") can display integers in fixed-point notation", function(test) {
test.equal(format.format("f")(42), "42.000000");
test.end();
});
tape("format(\"f\") can format negative zero as zero", function(test) {
test.equal(format.format("1f")(-0), "0.000000");
test.equal(format.format("1f")(-1e-12), "0.000000");
test.end();
});
tape("format(\",f\") does not group Infinity", function(test) {
test.equal(format.format(",f")(Infinity), "Infinity");
test.end();
});