Skip to content

Commit dc03617

Browse files
author
Dipak Sarkar
committed
fix nan issue for reverse fill
1 parent 2d1cafa commit dc03617

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/number-format.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function NumberFormat(config = options) {
3838
function toFixed(numbers, precision) {
3939
// eslint-disable-next-line no-restricted-properties
4040
var exp = Math.pow(10, precision);
41-
var float = parseFloat(numbers) / exp;
41+
var float = parseFloat(numbers) / exp || 0;
4242
return float.toFixed(fixed(precision));
4343
}
4444

tests/unit/number-format.reverse-fill.spec.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ import NumberFormat from "../../src/number-format";
33
describe("when enabled reverse fill", () => {
44
const numberFormat = new NumberFormat({
55
reverseFill: true,
6+
prefix: "$",
67
});
78
it("should return as follows", () => {
8-
expect(numberFormat.format("sdfgasd55468.546")).toEqual("554,685.46");
9-
expect(numberFormat.format("sdfgasd55468.546")).toEqual("554,685.46");
10-
expect(numberFormat.format("sdfgasd55468.546-")).toEqual("-554,685.46");
11-
expect(numberFormat.format("-1234.6512")).toEqual("-123,465.12");
12-
expect(numberFormat.format("0")).toEqual("0.00");
9+
expect(numberFormat.format("sdfgasd55468.546")).toEqual("$554,685.46");
10+
expect(numberFormat.format("sdfgasd55468.546")).toEqual("$554,685.46");
11+
expect(numberFormat.format("sdfgasd55468.546-")).toEqual("-$554,685.46");
12+
expect(numberFormat.format("-1234.6512")).toEqual("-$123,465.12");
13+
expect(numberFormat.format("0")).toEqual("$0.00");
14+
});
15+
it("should return as follows", () => {
16+
expect(numberFormat.format("sdfgasd55468.546")).toEqual("$554,685.46");
17+
expect(numberFormat.format("sdfgasd55468.546")).toEqual("$554,685.46");
18+
expect(numberFormat.format("sdfgasd55468.546-")).toEqual("-$554,685.46");
19+
expect(numberFormat.format("-1234.6512")).toEqual("-$123,465.12");
20+
expect(numberFormat.format(0)).toEqual("$0.00");
1321
});
1422
it("should return as follows", () => {
1523
expect(numberFormat.unformat("sdfgasd55468.546")).toEqual("554685.46");

0 commit comments

Comments
 (0)