Skip to content

Commit

Permalink
fix(fmt): fix the case when mantissa exceeds 10 by rounding and expon…
Browse files Browse the repository at this point in the history
…ent is negative (#5279)
  • Loading branch information
kt3k authored Jul 4, 2024
1 parent 5303767 commit 442a497
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fmt/printf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ class Printf {
if (10 <= mantissa) {
mantissa = 1;
const r = parseInt(esign + e) + 1;
e = r.toString();
e = Math.abs(r).toString();
esign = r < 0 ? "-" : "+";
}
}
Expand Down
1 change: 1 addition & 0 deletions fmt/printf_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Deno.test("sprintf() handles floats", function () {
assertEquals(sprintf("%.3e", 1.9999), "2.000e+00");
assertEquals(sprintf("%.3e", 29.99999), "3.000e+01");
assertEquals(sprintf("%.3e", 999999), "1.000e+06");
assertEquals(sprintf("%.3e", 0.000099999), "1.000e-04");
});
Deno.test("sprintf() handles floatE", function () {
assertEquals(sprintf("%E", 4), "4.000000E+00");
Expand Down

0 comments on commit 442a497

Please sign in to comment.