Merge pull request #15755 from calixteman/rounding_printf
[JS] Fix a rounding issue in printf (bug 1802888)
This commit is contained in:
commit
33f9d1aab2
@ -155,10 +155,11 @@ class Util extends PDFObject {
|
|||||||
}
|
}
|
||||||
if (decPart.length > 2) {
|
if (decPart.length > 2) {
|
||||||
decPart = `${decimalSep}${decPart.substring(2)}`;
|
decPart = `${decimalSep}${decPart.substring(2)}`;
|
||||||
} else if (cFlags & HASH) {
|
|
||||||
decPart = ".";
|
|
||||||
} else {
|
} else {
|
||||||
decPart = "";
|
if (decPart === "1") {
|
||||||
|
intPart += Math.sign(arg);
|
||||||
|
}
|
||||||
|
decPart = cFlags & HASH ? "." : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,6 +280,18 @@ describe("Scripting", function () {
|
|||||||
`util.printf("Decimal number: %,0.2f", -12.34567)`
|
`util.printf("Decimal number: %,0.2f", -12.34567)`
|
||||||
);
|
);
|
||||||
expect(value).toEqual("Decimal number: -12.35");
|
expect(value).toEqual("Decimal number: -12.35");
|
||||||
|
|
||||||
|
value = await myeval(`util.printf("Decimal number: %,0.0f", 4.95)`);
|
||||||
|
expect(value).toEqual("Decimal number: 5");
|
||||||
|
|
||||||
|
value = await myeval(`util.printf("Decimal number: %,0.0f", 4.49)`);
|
||||||
|
expect(value).toEqual("Decimal number: 4");
|
||||||
|
|
||||||
|
value = await myeval(`util.printf("Decimal number: %,0.0f", -4.95)`);
|
||||||
|
expect(value).toEqual("Decimal number: -5");
|
||||||
|
|
||||||
|
value = await myeval(`util.printf("Decimal number: %,0.0f", -4.49)`);
|
||||||
|
expect(value).toEqual("Decimal number: -4");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should print a string with no argument", async () => {
|
it("should print a string with no argument", async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user