diff --git a/src/components/ui/form-numeric-input.tsx b/src/components/ui/form-numeric-input.tsx index 1359d18..7fafbab 100644 --- a/src/components/ui/form-numeric-input.tsx +++ b/src/components/ui/form-numeric-input.tsx @@ -99,15 +99,23 @@ const FormNumericInput = React.forwardRef( numValue = 0 } + // Round the current value to avoid floating-point precision issues in comparisons + const decimalPlaces = getDecimalPlaces() + numValue = Math.round(numValue * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces) + // Snap to nearest increment first, then move one increment in the desired direction if (direction > 0) { // For increment: round up to next increment value, ensuring at least one increment is added - const snapped = Math.ceil(numValue / numIncrement) * numIncrement - numValue = snapped > numValue ? snapped : snapped + numIncrement + const steps = Math.round((numValue / numIncrement) * 1e10) / 1e10 // Avoid floating-point errors in division + const snappedSteps = Math.ceil(steps) + const snapped = Math.round((snappedSteps * numIncrement) * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces) + numValue = snapped > numValue ? snapped : Math.round(((snappedSteps + 1) * numIncrement) * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces) } else { // For decrement: round down to previous increment value, ensuring at least one increment is subtracted - const snapped = Math.floor(numValue / numIncrement) * numIncrement - numValue = snapped < numValue ? snapped : snapped - numIncrement + const steps = Math.round((numValue / numIncrement) * 1e10) / 1e10 // Avoid floating-point errors in division + const snappedSteps = Math.floor(steps) + const snapped = Math.round((snappedSteps * numIncrement) * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces) + numValue = snapped < numValue ? snapped : Math.round(((snappedSteps - 1) * numIncrement) * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces) } numValue = Math.max(min, numValue) diff --git a/src/locales/de.ts b/src/locales/de.ts index 9225eeb..dbd2538 100644 --- a/src/locales/de.ts +++ b/src/locales/de.ts @@ -314,6 +314,10 @@ export const de = { timePickerApply: "Übernehmen", timePickerCancel: "Abbrechen", + // Input field placeholders + min: "Min", + max: "Max", + // Sorting sortByTime: "Nach Zeit sortieren", sortByTimeNeeded: "Dosen sind nicht in chronologischer Reihenfolge. Klicken zum Sortieren.", diff --git a/src/locales/en.ts b/src/locales/en.ts index 8e88eb5..87eacb7 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -287,6 +287,10 @@ export const en = { timePickerApply: "Apply", timePickerCancel: "Cancel", + // Input field placeholders + min: "Min", + max: "Max", + // Sorting sortByTime: "Sort by time", sortByTimeNeeded: "Doses are not in chronological order. Click to sort.",