mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
fix(slider): fix floating point precision issues in SingleSlider and DualRangeSlider
JavaScript floating point arithmetic causes values like 1.1 to become 1.1000000000000014. Add precision limiting to 2 decimal places in snapToStep function for both sliders.
This commit is contained in:
@@ -206,7 +206,9 @@ const stepToDecimals = (step: number): number => {
|
||||
const snapToStep = (value: number, segmentMultiplier?: number): number => {
|
||||
const effectiveStep = segmentMultiplier ? props.step * segmentMultiplier : props.step
|
||||
const steps = Math.round((value - props.min) / effectiveStep)
|
||||
return Math.max(props.min, Math.min(props.max, props.min + steps * effectiveStep))
|
||||
const rawValue = Math.max(props.min, Math.min(props.max, props.min + steps * effectiveStep))
|
||||
// Fix floating point precision issues, limit to 2 decimal places
|
||||
return Math.round(rawValue * 100) / 100
|
||||
}
|
||||
|
||||
const startDrag = (handle: 'min' | 'max', event: PointerEvent) => {
|
||||
|
||||
@@ -82,7 +82,9 @@ const stepToDecimals = (step: number): number => {
|
||||
|
||||
const snapToStep = (value: number): number => {
|
||||
const steps = Math.round((value - props.min) / props.step)
|
||||
return Math.max(props.min, Math.min(props.max, props.min + steps * props.step))
|
||||
const rawValue = Math.max(props.min, Math.min(props.max, props.min + steps * props.step))
|
||||
// Fix floating point precision issues, limit to 2 decimal places
|
||||
return Math.round(rawValue * 100) / 100
|
||||
}
|
||||
|
||||
const startDrag = (event: PointerEvent) => {
|
||||
|
||||
Reference in New Issue
Block a user