try icon indicating copy to clipboard operation
try copied to clipboard

Double values incorrect/unexpected value

Open DgBodego opened this issue 7 months ago • 0 comments

Bug Description

I am doing a Visual C# training and I am using .NET editor for practising. I am checking the different outputs for different real values and representation of 1/3.

The code I used: (Visual C#)

//DECLARATION

decimal a=1m;
decimal b=3m;
decimal c=a/b;

//CONSOLE OUTPUT

Console.WriteLine((int)c);
Console.WriteLine((float)c);
Console.WriteLine((double)c);
Console.WriteLine((decimal)c);

The values retrieved shall be:

0
0.33333334
0.33333333333333334
0.3333333333333333333333333333

But I am getting:

0
0.33333334
0.33333333333333337
0.3333333333333333333333333333

I check the technical documentation at Microsoft, and it is explained that there should be some rounding errors. I am assuming that this is not a rounding error but an error: double value should end on 3 or 4, it doesn´t matter if it is rounded, rounded up, rounded down or truncated, but it shouldn´t be 7 ever.

URL

I found this error in the Microsoft Learn webpage I was working in:

https://learn.microsoft.com/en-us/training/modules/csharp-basic-operations/3-exercise-math-operators

What kind of error was it?

  • [ X] Other: It was a wrong calculation or, at least, unexpected.

Screenshots

Image

System Info:

  • OS: Windows 11 Pro 24H2 26100.4061

  • Browser: Microsoft Edge 136.0.3240.76 (Official build) (64-bit)

DgBodego avatar May 22 '25 02:05 DgBodego