diff --git a/src/scripting_api/util.js b/src/scripting_api/util.js index 5220c5b64..551a3fb60 100644 --- a/src/scripting_api/util.js +++ b/src/scripting_api/util.js @@ -153,7 +153,12 @@ class Util extends PDFObject { ? Math.abs(arg - intPart).toFixed(nPrecision) : Math.abs(arg - intPart).toString(); if (decPart.length > 2) { - decPart = `${decimalSep}${decPart.substring(2)}`; + if (/^1\.0+$/.test(decPart)) { + intPart += Math.sign(arg); + decPart = `${decimalSep}${decPart.split(".")[1]}`; + } else { + decPart = `${decimalSep}${decPart.substring(2)}`; + } } else { if (decPart === "1") { intPart += Math.sign(arg); diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index e472a810c..57b0c52e6 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -2468,4 +2468,32 @@ describe("Interaction", () => { ); }); }); + + describe("Correctly format numbers", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("bug1918115.pdf", getSelector("33R")); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the computed value is correct", async () => { + await Promise.all( + pages.map(async ([browserName, page], i) => { + await waitForScripting(page); + + const inputSelector = getSelector("33R"); + await page.click(inputSelector); + await page.type(inputSelector, "7"); + await page.click(getSelector("34R")); + await page.waitForFunction( + `${getQuerySelector("35R")}.value === "324,00"` + ); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 01dd1d125..fc0f6e0e8 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -667,3 +667,4 @@ !bug1708040.pdf !issue18694.pdf !issue18693.pdf +!bug1918115.pdf diff --git a/test/pdfs/bug1918115.pdf b/test/pdfs/bug1918115.pdf new file mode 100755 index 000000000..927fd12bf Binary files /dev/null and b/test/pdfs/bug1918115.pdf differ