Skip to content

Commit 694921c

Browse files
authored
Merge pull request #248 from richford/decimals-again
Format ints and numbers using as few zeros as possible in metadata table
2 parents 4f468b1 + 674a300 commit 694921c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

afqbrowser/site/client/js/table.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,24 @@ afqb.table.buildTable = function (error, useless, data) {
6464
return !isNaN(+e);
6565
}
6666

67+
function isInt(e) {
68+
return Number.isInteger(+e);
69+
}
70+
6771
function identity (arg) {
6872
return arg;
6973
}
7074

7175
if (column.every(isBinary)) {
7276
afqb.table.subFormats[key] = d3.format("0b");
7377
} else if (column.every(isNum)) {
74-
afqb.table.subFormats[key] = d3.format(".7g");
78+
if (column.every(isInt)) {
79+
afqb.table.subFormats[key] = d3.format("d");
80+
} else {
81+
afqb.table.subFormats[key] = function (n) {
82+
return parseFloat(d3.format(".4f")(n));
83+
}
84+
}
7585
} else {
7686
afqb.table.subFormats[key] = identity;
7787
}

0 commit comments

Comments
 (0)