We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd02901 commit 1766d8eCopy full SHA for 1766d8e
src/format.js
@@ -55,12 +55,11 @@ function processValue(value, maskObj, options) {
55
// Fix the decimal first, toFixed will auto fill trailing zero.
56
valObj.value = Number(valObj.value).toFixed(maskObj.fraction && maskObj.fraction.length);
57
// Convert number to string to trim off *all* trailing decimal zero(es)
58
- valObj.value = valObj.value.toString();
+ valObj.value = Number(valObj.value).toString();
59
60
// Fill back any trailing zero according to format
61
// look for last zero in format
62
const posTrailZero = maskObj.fraction && maskObj.fraction.lastIndexOf("0");
63
-
64
let [valInteger = "0", valFraction = ""] = valObj.value.split(".");
65
if (!valFraction || (valFraction && valFraction.length <= posTrailZero)) {
66
valFraction = (Number("0." + valFraction).toFixed(posTrailZero + 1)).replace("0.", "");
test/test.js
@@ -57,6 +57,12 @@ test("Precision", t => {
t.is(format("##,000.", 123456789.987654321), "123,456,790");
t.is(format("###,####.", 123456789.187654321), "1,2345,6789");
t.is(format("#'###'#00,", 123456789.087654321), "123'456'789");
+ t.is(format("#,##0.####", 1234567.890), "1,234,567.89");
+ t.is(format("#,##0.###0", 1234567.890), "1,234,567.8900");
+ t.is(format("#,##0.##0#", 1234567.890), "1,234,567.890");
+ t.is(format("#,##0.#0##", 1234567.890), "1,234,567.89");
+ t.is(format("#,##0.#", 1234567.890), "1,234,567.9");
+ t.is(format("#,###.", 1234567.890), "1,234,568");
});
67
68
/* Mask with prefix and/or suffix */
0 commit comments