r/softwareengineer • • 6d ago

Implicitly converting from double to decimal

Hi Guys, maybe you can relate or even help:

I‘ve been developing in vb.net (.net 8 still) for years now - and I know vb is fucked and .net8 is out of support, next year I‘m going to migrate to C# on .net10 (legacy code) - and it was always possible to declare a variable as decimal and implicitly initialize a double value ( like Dim var as Decimal = 1.5).

This has worked since I‘ve been on the project.
Now, last week I switched to VS2026, and from then on this wasn‘t possible anymore.

For the example above, the value of var would be something like 1.49999889789.

Funny thing is, It still works the old way for my coworker - same Ide, same sdk

Has anyone an explanation for said behaviour or, even better, knows if/how I can get back to the way I‘m used to?

I would really appreciate it.

It‘s a Winforms Application for Windows by the way.

1 Upvotes

3 comments sorted by

1

u/Agitated_Oven_6507 6d ago

This is a documented breaking change in .NET 11: https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions?WT.mc_id=DT-MVP-5003978. If you use a compiler that run on .NET 11, you are affected. In C# use the m suffix (1.5m). In VB.NET use the D suffix (1.5D).

1

u/IGeoorge3g 6d ago

Someone posted a warn yesterday about this topic (Reddit). Nice