Skip to content

Commit 8136472

Browse files
committed
Fix Slider snapping precision issue (#8819)
1 parent 9484c1c commit 8136472

File tree

1 file changed

+5
-0
lines changed
  • src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls

1 file changed

+5
-0
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,11 @@ private double SnapToTick(double value)
11891189
value = DoubleUtil.GreaterThanOrClose(value, (previous + next) * 0.5) ? next : previous;
11901190
}
11911191

1192+
// Normalize floating-point rounding errors introduced by
1193+
// repeated tick arithmetic (e.g. 0.1 + 0.2 ≠ 0.3 exactly in IEEE-754).
1194+
// This prevents visual artifacts like 1.1312000000000002.
1195+
value = Math.Round(value, 10);
1196+
11921197
return value;
11931198
}
11941199

0 commit comments

Comments
 (0)