Code First:
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
...
<xctk:SingleUpDown Value="{Binding floatvalue}" FormatString="F7" Minimum="0"/>
...
floatvalue is a property of float Type.
If the user type "8.76543212" in the SingleUpDown and then leave focus (Press Tab), the value will change to 8.7654320 (frequently) or 8.7654300 (seldom).
But if comment the {Binding } out,
<xctk:SingleUpDown Value="0.1234567" FormatString="F7" Minimum="0"/>
All works well.
In conclusion, there are two requirements to reproduce this issue: 1. Bind Value to a property; 2. Change focus after modifying.
I've added a customized Converter to capture the value before and after change, no help.
I've also tried to dig into the source code of NumericUpDown but I can not find any useful informations.
The behind C# code is simple:
public float floatvalue { get; set; }
The last digits of NumericUpDown should display precisely.
Well that's the problem with IEEE 754 - it's not super precise. Try using decimal
instead - it's a 128 bit datatype that will not round.
Compared to other floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations - decimal (C# Reference)