-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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.