DialogInput.numberRange displays floating-point artifacts (e.g. 19.900002) despite clean float inputs
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 3.5k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 11
Description
Expected behavior
When using DialogInput.numberRange with a float step (e.g., 0.1f) and a clean initial float value (e.g., 19.9f), the client-side UI should display the value cleanly as "19.9".
Observed/Actual behavior
The client UI displays floating-point artifacts, showing values like "19.900002" or "2.8000002" instead of the expected clean decimal. This happens even when the initial value and step are explicitly defined as clean floats.
Steps/models to reproduce
// Create a Dialog with a number range input using float values
DialogInput.numberRange("initialTime", Component.text("Initial Time"), 0.1f, 60f)
.initial(19.9f) // Clean float literal
.step(0.1f) // Clean float step
.build()
// Open this dialog to a player and observe the slider value.
Plugin and Datapack List
Paper version
Other
We have attempted several workarounds to fix this display issue, but none were successful due to API limitations:
-
Rounding the Initial Value:
We triedMath.round(val * 10.0) / 10.0before passing it to.initial(). The issue persists because thestep(0.1f)addition causes immediate floating-point drift in the client view. -
Using BigDecimal:
We attempted to useBigDecimalfor precision:
.initial(BigDecimal.valueOf(val).setScale(1, RoundingMode.HALF_UP).floatValue())
However, since the API only acceptsfloatforinitial()andstep(), converting back to float reintroduces the precision errors. -
Visual Workaround (Integer Multiplier):
We tried scaling values by 10 (0-600 range) to use integers and adding "(x0.1)" to the label. This fixes the display but degrades UX as users must mentally calculate the decimal.
Suggestion:
It would be helpful if DialogInput supported double orWe have attempted several workarounds to fix this display issue, but none were successful due to API limitations:
-
Rounding the Initial Value:
We triedMath.round(val * 10.0) / 10.0before passing it to.initial(). The issue persists because thestep(0.1f)addition causes immediate floating-point drift in the client view. -
Using BigDecimal:
We attempted to useBigDecimalfor precision:
.initial(BigDecimal.valueOf(val).setScale(1, RoundingMode.HALF_UP).floatValue())
However, since the API only acceptsfloatforinitial()andstep(), converting back to float reintroduces the precision errors. -
Visual Workaround (Integer Multiplier):
We tried scaling values by 10 (0-600 range) to use integers and adding "(x0.1)" to the label. This fixes the display but degrades UX as users must mentally calculate the decimal.
Suggestion:
It would be helpful if DialogInput supported double or BigDecimal to handle precision correctly, or if there was a way to specify a display format (e.g., %.1f) for the client UI to hide these artifacts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the DialogInput.numberRange API and trace how its float initial value and step are represented for the client UI. Reproduce the example with 19.9f and 0.1f, then identify where the displayed value gains its floating-point artifacts. Done means the slider displays clean decimal values without breaking the existing number-range behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100