Skip to content

Use scientific notation when number_to_text rounds up to 1e15 - #2069

Merged
aiongg merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h871-number-to-text-prints-16-digits
Oct 22, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h871-number-to-text-prints-16-digits

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/core/src/value.rs:354-367 (no existing issue): number_to_text prints 16 digits for numbers just below 1e15 that round up to 1e15.

Cause

number_to_text checked for scientific notation on the unrounded magnitude. A value just below 1e15, such as 999999999999999.9, took the fixed-point path. Rounding to 15 significant digits there produced the 16-digit text "1000000000000000".

Fix

After the existing scientific check, number_to_text now rounds the magnitude to 15 significant digits. If the rounded value reaches 1e15, it returns the scientific text. 999999999999999.9 now gives "1E+15", matching 1e15 itself.

Verified

  • Regression test value::tests::number_text_rounds_up_to_scientific_boundary: fails on main without the fix and passes with it (cargo test -p gridcraft-core number_text_rounds_up_to_scientific_boundary).
  • cargo xtask ci passes.

Not changed

The fixed-point formatting for other values and the small-magnitude (below 1e-9) scientific handling are unchanged. I did not test values that round up across other power-of-ten boundaries.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Improved number formatting at the 1e15 boundary to prevent rounded values from being displayed in misleading decimal notation.
    • Preserved standard decimal formatting for values that remain below the boundary.
    • Added coverage for positive and negative boundary cases.

Found while testing crates/core/src/value.rs:354-367

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: storytold/gridcraft/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ccc6daf0-c63c-40c6-bdaa-9a302322af75
📥 Commits

Reviewing files that changed from the base of the PR and between 68e58a2 and f29ac7d.

📒 Files selected for processing: 1
  • crates/core/src/value.rs

Limit details: You’ve used all 10 included reviews currently available.

📝 Walkthrough

number_to_text now switches to scientific notation when rounding to 15 significant digits reaches 1e15. Tests cover positive and negative values that round to the boundary, and a value that remains below it.

Changes: Number formatting

Layer / File(s) Summary
Handle the rounding boundary
crates/core/src/value.rs
number_to_text checks whether 15-significant-digit rounding reaches 1e15 and uses scientific notation in that case. Tests cover positive and negative boundary-rounding values and confirm that 999999999999999.0 remains decimal-formatted.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: echelon

Merge Risk: ⚪ Minimal · up to f29ac

The boundary-formatting change is mergeable with normal validation.

Architecture risk: 🔵 Low · up to f29ac

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/core/src/value.rs: number_to_text now detects values whose 15-digit formatted magnitude rounds to at least 1e15 and emits scientific notation.
  • observed — Modified behavior in crates/core/src/value.rs: Added tests verifying scientific notation for positive and negative values rounding up to 1e15, while 999999999999999.0 remains decimal-formatted.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using scientific notation when number_to_text rounds a value up to 1e15.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Comment @coderabbitai help to get the list of available commands.

@aiongg
aiongg merged commit b40c0a6 into storytold:main Oct 22, 2026
2 checks passed
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.

2 participants