generated from nhcarrigan/template
fix: display sub-one values with two decimal places (#25)
This commit is contained in:
@@ -73,7 +73,9 @@ const formatSuffix = (value: number): string => {
|
|||||||
return `${(value / threshold).toFixed(2)}${suffix}`;
|
return `${(value / threshold).toFixed(2)}${suffix}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value.toFixed(1);
|
return value < 1
|
||||||
|
? value.toFixed(2)
|
||||||
|
: value.toFixed(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,8 +28,12 @@ describe("formatNumber", () => {
|
|||||||
expect(formatNumber(-1000)).toBe("-1.00K");
|
expect(formatNumber(-1000)).toBe("-1.00K");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format zero as '0.0'", () => {
|
it("should format zero as '0.00'", () => {
|
||||||
expect(formatNumber(0)).toBe("0.0");
|
expect(formatNumber(0)).toBe("0.00");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should format small decimal values with two decimal places", () => {
|
||||||
|
expect(formatNumber(0.01)).toBe("0.01");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user