why this simple WPF code get wrong result(1.1+2.2=3.3000000003)

兰树豪 381 Reputation points
2022-10-14T02:05:17.017+00:00

see my pictur250217-1122.jpge, it's a strange error, thanks

Developer technologies Windows Presentation Foundation
Developer technologies XAML
Developer technologies C#
{count} votes

Accepted answer
  1. Lex Li (Microsoft) 6,037 Reputation points Microsoft Employee
    2022-10-14T05:21:34.05+00:00

    If you read more about precision and accuracy in floating point calculation, you will see it is perfect normal and machine dependent,

    https://learn.microsoft.com/en-us/office/troubleshoot/access/floating-calculations-info

    To achieve some accuracy, you can use decimal type,

    https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.