fix: format slider values to decimal places#38
fix: format slider values to decimal places#38xWalfie-SMR wants to merge 1 commit intoRhythia:indevfrom
Conversation
xWalfie-SMR
commented
Apr 17, 2026
- added getDecimalPlaces() that takes the step value of a slider and returns its decimal index rounded
- updateSlider() now uses getDecimalPlaces() to round the slider value to avoid floating point errors
- added getDecimalPlaces() that takes the step value of a slider and returns its decimal index rounded - updateSlider() now uses getDecimalPlaces() to round the slider value to avoid floating point errors
There was a problem hiding this comment.
Pull request overview
This PR adjusts how slider values are rendered in the settings UI by formatting slider values to a fixed number of decimal places derived from the slider’s Step, aiming to reduce visible floating-point artifacts.
Changes:
- Updated
updateSlider()to format slider values using a fixed-point format string with step-derived precision. - Added
getDecimalPlaces(step)helper to infer the number of decimal places from the slider step.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -327,6 +329,16 @@ private void updateSlider(HSlider slider, LineEdit lineEdit, double value) | |||
| slider.SetValueNoSignal(value); | |||
There was a problem hiding this comment.
updateSlider formats the text using a fixed-point format, but it does not actually round/snap the underlying value used for slider.SetValueNoSignal(value). This means floating-point artifacts can still persist in the slider/setting value (even if the text is rounded), and equality checks elsewhere (e.g. setting.GetVariant() != value) can still churn on tiny deltas. Consider rounding/snap-to-step the numeric value first (and then using that rounded value consistently for both the LineEdit text and the slider/set-variant paths).
| // round step to remove floating point errors | ||
| double roundedStep = Math.Round(step, 3); | ||
|
|
||
| string stepStr = roundedStep.ToString(System.Globalization.CultureInfo.InvariantCulture); |
There was a problem hiding this comment.
getDecimalPlaces hardcodes Math.Round(step, 3), so the computed decimal place count will be incorrect for step values that legitimately require more than 3 decimal places (e.g. 0.0005 would be treated as 0.001). If this helper is meant to be generally correct for any slider step, consider deriving the decimal places without truncating precision (or making the precision limit an explicit constant tied to supported step values).
| // round step to remove floating point errors | |
| double roundedStep = Math.Round(step, 3); | |
| string stepStr = roundedStep.ToString(System.Globalization.CultureInfo.InvariantCulture); | |
| decimal decimalStep = Math.Abs((decimal)step); | |
| string stepStr = decimalStep | |
| .ToString(System.Globalization.CultureInfo.InvariantCulture) | |
| .TrimEnd('0'); |
|
Thank you for the fix, the code looks good, but unfortunately there is another one waiting to be merged after PRs #35 & #37 are finished as they require some adjustment and fixes. I'm sorry this wasn't communicated anywhere as the bulk of contributions are discussed and reviewed through the Discord server rather than on GitHub, which I recognize is a flaw in our process. |