From 94b175f3d6a608acc56fc63906a7f9140de83ef5 Mon Sep 17 00:00:00 2001 From: zepumph Date: Wed, 25 May 2022 10:22:06 -0600 Subject: [PATCH] fix javascript number imprecision when snapping to tick mark, https://github.com/phetsims/ratio-and-proportion/issues/457 --- js/common/view/RatioHalf.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/common/view/RatioHalf.ts b/js/common/view/RatioHalf.ts index 49be235b..edf84320 100644 --- a/js/common/view/RatioHalf.ts +++ b/js/common/view/RatioHalf.ts @@ -270,7 +270,9 @@ class RatioHalf extends Rectangle { // iterate through model values of each tick mark for ( let i = TOTAL_RANGE.min; i < TOTAL_RANGE.max; i += tickMarkStep ) { if ( Math.abs( yValue - i ) < tickMarkStep * SNAP_TO_TICK_MARK_THRESHOLD ) { - return i; + + // Bug occurs when dragging to the top with tick marks enabled, the value is 1, but snaps to .999999 unless rounded + return rapConstants.toFixed( i ); // eslint-disable-line bad-sim-text } } }