From bcdfc9f83dfefea5e09b744d20fa98f6a647204e Mon Sep 17 00:00:00 2001 From: Roman Pominov Date: Wed, 3 May 2023 14:36:01 +0400 Subject: [PATCH] Fix floating point math issue in scrub (#1562) ## Description Fix of the bug reported in https://discord.com/channels/955905230107738152/1102991527254446182: 1. Set value of any input that you can scrub to 1.3 2. Scrub to decrease it by 1 to 0.3 3. The value gets set 0.30000000000000004 --- .../src/components/primitives/numeric-gesture-control.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/design-system/src/components/primitives/numeric-gesture-control.ts b/packages/design-system/src/components/primitives/numeric-gesture-control.ts index eb147f3508..a345c32eae 100644 --- a/packages/design-system/src/components/primitives/numeric-gesture-control.ts +++ b/packages/design-system/src/components/primitives/numeric-gesture-control.ts @@ -57,7 +57,8 @@ const getValueDefault = ( maxValue = Number.MAX_SAFE_INTEGER, }: NumericScrubOptions ) => { - const value = state.value + movement; + // toFixed is needed to fix `1.3 - 1 = 0.30000000000000004` + const value = Number((state.value + movement).toFixed(2)); if (value < minValue) { return minValue; }