这是indexloc提供的服务,不要输入任何密码
Skip to content

Fix decimal scientific notation #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions oxifmt.typ
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,7 @@
// Normalize decimals with larger scales than is needed
let fractional = fractional.sum(default: "").trim("0", at: end)
let (integral, fractional, exponent) = if num > -1 and num < 1 and fractional != "" {
let first-non-zero = fractional.position("1")
if first-non-zero == none { first-non-zero = fractional.position("2") }
if first-non-zero == none { first-non-zero = fractional.position("3") }
if first-non-zero == none { first-non-zero = fractional.position("4") }
if first-non-zero == none { first-non-zero = fractional.position("5") }
if first-non-zero == none { first-non-zero = fractional.position("6") }
if first-non-zero == none { first-non-zero = fractional.position("7") }
if first-non-zero == none { first-non-zero = fractional.position("8") }
if first-non-zero == none { first-non-zero = fractional.position("9") }
let first-non-zero = fractional.codepoints().position(s => s != "0")
assert(first-non-zero != none, message: "String formatter internal error: expected non-zero fractional digit")

// Integral part is zero
Expand Down
3 changes: 3 additions & 0 deletions tests/strfmt-tests.typ
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
assert.eq(strfmt("{:e}", decimal("132423")), "1.32423e5")
assert.eq(strfmt("{:e}", decimal("-132423")), "-1.32423e5")
assert.eq(strfmt("{:011.5}", decimal("1234.5")), "01234.50000")

// Issue #23: decimal exponential
assert.eq(strfmt("{:e}", decimal("0.31")), "3.1e-1")
}
// Issue #16: large numbers
#{
Expand Down