godotengine / godotengine/godot
`SpinBox` and `EditorSpinSlider` do not take into account that `min_value` may have more decimals than `step`
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in 4.3 dev.
### System information
Kubuntu 24.04
### Issue description
`SpinBox` and `EditorSpinSlider` use `step`'s decimals to round the displayed value. However, this does not take into account that `min_value` may not be a multiple of `step`, so the `value` may have more decimals than `step`:
Here `value` is snapped to 0.2, 3.2, 6.2, 9.2, ...:

`print($SpinBox.value)` also outputs `3.2`, not `3`.
* See also https://github.com/godotengine/godot/issues/93332#issuecomment-2178122183.
---
https://github.com/godotengine/godot/blob/9a4942f2f59af3c9a17187e0ed20ffa40d5f9514/scene/gui/spin_box.cpp#L43-L47
https://github.com/godotengine/godot/blob/9a4942f2f59af3c9a17187e0ed20ffa40d5f9514/editor/gui/editor_spin_slider.cpp#L47-L49
```c++
void SpinBox::_update_text(bool p_keep_line_edit) {
print_line(get_value()); // 3.2
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
print_line(value); // 3
```
### Steps to reproduce
See above.
### Minimal reproduction project (MRP)
N/A
Contributor guide
Research direction
Start with scene/gui/spin_box.cpp and editor/gui/editor_spin_slider.cpp at the linked rounding logic. Reproduce the case where min_value is not a multiple of step and compare the displayed value with the underlying value. Done means both controls preserve the necessary decimals for values such as 3.2 instead of displaying 3.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100