diff --git a/oxifmt.typ b/oxifmt.typ index c12882e..cd774a8 100644 --- a/oxifmt.typ +++ b/oxifmt.typ @@ -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 diff --git a/tests/strfmt-tests.typ b/tests/strfmt-tests.typ index 25c5114..a2065fb 100644 --- a/tests/strfmt-tests.typ +++ b/tests/strfmt-tests.typ @@ -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 #{