Skip to content

Conversation

@mayagbarnes
Copy link
Collaborator

Describe your changes

When using the increment/decrement buttons or arrow keys on st.number_input, floating point arithmetic errors could cause values to display incorrectly:
Before:
Screenshot 2025-12-29 at 8 25 24 p m

This PR improves increment/decrement with precise calculation, handling both standard notation (0.01) and scientific notation (1e-7).

Note: scientific notation (very small step values) failed completely in number input before because JS automatically converts very small #s to scientific notation - this PR solves that bug as well.

Testing Plan

  • JS Unit Tests: ✅ Added
  • E2E Tests: ✅ Added
  • Manual Testing: ✅

@mayagbarnes mayagbarnes added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Dec 30, 2025
@snyk-io
Copy link
Contributor

snyk-io bot commented Dec 30, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 30, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13484/streamlit-1.52.2-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13484.streamlit.app (☁️ Deploy here if not accessible)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 30, 2025

📈 Frontend coverage change detected

The frontend unit test (vitest) coverage has increased by 0.0200%

  • Current PR: 86.5400% (12789 lines, 1721 missed)
  • Latest develop: 86.5200% (12768 lines, 1720 missed)

✅ Coverage change is within normal range.

📊 View detailed coverage comparison

@mayagbarnes mayagbarnes changed the title [WIP] Improve st.number_input precision Improve st.number_input precision Dec 30, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes floating point arithmetic errors in st.number_input that occurred during increment/decrement operations. The key improvement is the introduction of precise step arithmetic using scale-based integer math to avoid issues like 0.1 + 0.01 = 0.11000000000000001. Additionally, the PR adds support for very small step values that JavaScript represents in scientific notation (e.g., 1e-7), which previously failed completely.

Key changes:

  • New getDecimalPlaces function to extract decimal precision from both standard and scientific notation
  • New preciseStepArithmetic function to perform accurate increment/decrement operations
  • Updated formatValue to use getDecimalPlaces for consistent precision handling
  • Comprehensive test coverage across unit, integration, and E2E tests

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontend/lib/src/components/widgets/NumberInput/utils.ts Added getDecimalPlaces and preciseStepArithmetic functions; updated formatValue to use new precision logic
frontend/lib/src/components/widgets/NumberInput/utils.test.ts Added comprehensive unit tests for new functions covering standard decimals, scientific notation, and edge cases
frontend/lib/src/components/widgets/NumberInput/NumberInput.tsx Integrated preciseStepArithmetic into increment/decrement callbacks
frontend/lib/src/components/widgets/NumberInput/NumberInput.test.tsx Added integration tests verifying precise arithmetic through button clicks and keyboard interactions
e2e_playwright/st_number_input.py Added two new number inputs (18 and 19) for testing scientific notation steps
e2e_playwright/st_number_input_test.py Added four E2E tests for floating point precision and scientific notation handling
e2e_playwright/__snapshots__/linux/st_number_input_test/st_number_input-value_none_min_1[dark_theme-chromium].png Updated snapshot reflecting the increased number input count

@sfc-gh-mbarnes sfc-gh-mbarnes marked this pull request as ready for review January 4, 2026 01:35
Copy link
Contributor

@sfc-gh-nbellante sfc-gh-nbellante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!! 🙌 It's been bothering me forever

@mayagbarnes mayagbarnes merged commit 1e5e9a9 into develop Jan 6, 2026
43 checks passed
@mayagbarnes mayagbarnes deleted the number-input-precision branch January 6, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants