[JS] Correctly format floating numbers when they're close to an integer (bug 1918115)
This commit is contained in:
parent
870394d22b
commit
ca95264e8b
@ -153,7 +153,12 @@ class Util extends PDFObject {
|
|||||||
? Math.abs(arg - intPart).toFixed(nPrecision)
|
? Math.abs(arg - intPart).toFixed(nPrecision)
|
||||||
: Math.abs(arg - intPart).toString();
|
: Math.abs(arg - intPart).toString();
|
||||||
if (decPart.length > 2) {
|
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 {
|
} else {
|
||||||
if (decPart === "1") {
|
if (decPart === "1") {
|
||||||
intPart += Math.sign(arg);
|
intPart += Math.sign(arg);
|
||||||
|
|||||||
@ -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"`
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -667,3 +667,4 @@
|
|||||||
!bug1708040.pdf
|
!bug1708040.pdf
|
||||||
!issue18694.pdf
|
!issue18694.pdf
|
||||||
!issue18693.pdf
|
!issue18693.pdf
|
||||||
|
!bug1918115.pdf
|
||||||
|
|||||||
BIN
test/pdfs/bug1918115.pdf
Executable file
BIN
test/pdfs/bug1918115.pdf
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user