Fix: Preserve numeric conversion accuracy in ColorSliderTextFieldConfiguration#11
Merged
noppefoxwolf merged 1 commit intonoppefoxwolf:mainfrom Sep 21, 2025
Conversation
…ation` Fixes isontheline/pro.webssh.net#1412 When converting text input back and forth between `String` ↔︎ `Double` ↔︎ `String`, floating-point precision errors caused off-by-one truncations.
Owner
|
@isontheline Thank you for your PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey @noppefoxwolf 👋
Thank you so much for your awesome ColorPicker library 🙏
I'm encountering an issue (isontheline/pro.webssh.net#1412) where user can't put some RGB values.
Do you think you can apply this PR on your main branch?
Have you a better way to fix it?
Have a great day ☀️
===========
Problem
When converting text input back and forth between
String↔︎Double↔︎String, floating-point precision errors caused off-by-one truncations.Example:
96(percent mode)0.96Int(value * 100)yields95.9999…→ truncated to95This resulted in unexpected value loss.
Solution
Applied rounding before casting to
Intinside allvalueToTextclosures (hex,radius,percent):Additionally, values are clamped to the valid ranges (
0...255,0...360,0...100) to avoid accidental out-of-range results.Impact
96remains96)Testing