diff --git a/src/scripting_api/util.js b/src/scripting_api/util.js index 6c8130ceb5b42d..262c1f0aa98f3c 100644 --- a/src/scripting_api/util.js +++ b/src/scripting_api/util.js @@ -155,10 +155,11 @@ class Util extends PDFObject { } if (decPart.length > 2) { decPart = `${decimalSep}${decPart.substring(2)}`; - } else if (cFlags & HASH) { - decPart = "."; } else { - decPart = ""; + if (decPart === "1") { + intPart += Math.sign(arg); + } + decPart = cFlags & HASH ? "." : ""; } } diff --git a/test/unit/scripting_spec.js b/test/unit/scripting_spec.js index 9ae19cf3dfb481..bfcc10a567a846 100644 --- a/test/unit/scripting_spec.js +++ b/test/unit/scripting_spec.js @@ -280,6 +280,18 @@ describe("Scripting", function () { `util.printf("Decimal number: %,0.2f", -12.34567)` ); 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 () => {