Skip to content

fix: preserve zero fractions when formatting integral floats - #1334

Open
rksharma-owg wants to merge 1 commit into
google:masterfrom
rksharma-owg:codex/fix-integral-float-fraction
Open

fix: preserve zero fractions when formatting integral floats#1334
rksharma-owg wants to merge 1 commit into
google:masterfrom
rksharma-owg:codex/fix-integral-float-fraction

Conversation

@rksharma-owg

Copy link
Copy Markdown

std.format("%f", 1e20) produces "100000000000000000000.729344", even though the input is an exactly representable whole number. Multiplying that value by the requested precision introduces rounding error before the remainder is calculated.

Preserve the whole value and a zero fraction when the input is integral. Non-integral inputs retain the existing rounding path. Regression tests cover large positive and negative integers, the largest safe integer, precision zero, signs, padding, and a fractional value that rounds into the next integer.

Refs #1331. This addresses its spurious %f fractional digits; the separate exact-decimal %d conversion discrepancy remains outside this change. This is independent of #1332, which validates dynamic width and precision.

Validation: the new regression failed before the fix; all 173 scripts in test_suite/run_tests.sh pass after rebuilding. git diff --check and formatting of test_suite/format.jsonnet pass. The stdlib formatter reports only existing differences outside the changed lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant