microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.27k stars 674 forks source link

NumberBox displays double 3.12 as 3.1999999999..... #9826

Open Petrarca181 opened 1 month ago

Petrarca181 commented 1 month ago

Describe the bug

As in title, any other number is ok only 3.12 is 3.199999999999...

image image

Steps to reproduce the bug

Expected behavior

No response

Screenshots

No response

NuGet package version

None

Windows version

No response

Additional context

No response

DarranRowe commented 1 month ago

I wonder if the actual value stored for 3.12 is far enough away from 3.12 that Xaml doesn't round it correctly. Well, floating point numbers are hard.

The actual value stored for 3.12 is: float: 3.11999988555908203125 double: 3.12000000000000010658141036401502788066864013671875

These are the C/C++ types, but float is single precision (32 bit) and double is double precision (64 bit).

Petrarca181 commented 1 month ago

I wonder if the actual value stored for 3.12 is far enough away from 3.12 that Xaml doesn't round it correctly. Well, floating point numbers are hard.

The actual value stored for 3.12 is: float: 3.11999988555908203125 double: 3.12000000000000010658141036401502788066864013671875

These are the C/C++ types, but float is single precision (32 bit) and double is double precision (64 bit).

NuberBox Value propertry is double. I can bind it to the ViewModel or asign value code behind, with same result.

DarranRowe commented 1 month ago

Then it is internally getting converted to float.

Just to clarify something important. There is a disagreement between the value in the original report. There is an image that states 3.1199999.... but the title states 3.199999..... The image contains a value that would be understandable for a double->float conversion. The value in the title is completely unexpected. So I am making an assumption that the value in the title is a typo where the value in the image is the correct value.

Balkoth commented 1 month ago

You could try to use decimal, but then you are even more effed, because you can not bind to decimal and need a converter.