Comfy-Org / Comfy-Org/ComfyUI_frontend
Float precision errors when using increment/decrement buttons with high precision settings
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
# Float precision errors when using increment/decrement buttons with high precision settings
## Description
When using the increment/decrement buttons on float widgets, precision errors occur if the user's Float Rounding Precision setting is higher than the widget's step precision.
## Steps to Reproduce
1. Go to Settings → Set "Float Rounding Precision" to 6
2. Add a StyleModelApply node (or any node with `step: 0.001`)
3. Set strength to 0.223 (by typing)
4. Click the up arrow button once
5. Save the workflow
6. Check the JSON file - strength is saved as `0.22399999999999998` instead of `0.224`
## Expected Behavior
Clicking up from 0.223 should result in 0.224 being saved.
## Actual Behavior
The value is saved with floating-point precision errors like `0.22399999999999998`.
## Root Cause
When incrementing/decrementing:
- The step value (0.001) has inherent precision 3
- JavaScript calculates: `0.223 + 0.001 = 0.22400000000000000466`
- The rounding function uses precision 6 (user setting)
- Precision 6 rounding cannot fix precision 3 arithmetic errors
## Additional Context
- This only happens with button clicks, not when typing values directly
- This is a different issue than #4291 (which fixes the base rounding calculation)
- Affects any widget where user's precision setting > step's implied precision
## Potential Solutions
1. Use `max(stepPrecision, userPrecision)` for rounding after increment/decrement
2. Apply step-based rounding immediately after arithmetic operations
3. Warn users when precision setting exceeds step precision
4. Round to step precision first, then to user precision
## System Info
- ComfyUI Frontend version: latest
- Tested on PR #4291 branch (issue exists with or without that PR)
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-4350-Float-precision-errors-when-using-increment-decrement-buttons-with-high-precision-sett-2266d73d365081dfaf01facb4214c270) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.