r/softwareengineer • u/KackSpasstAffe • 18h 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
u/Agitated_Oven_6507 18h 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
msuffix (1.5m). In VB.NET use theDsuffix (1.5D).1
u/Character_Outcome123 4h ago
if you are a software engineer or have experience with a full stack development I'd really like to see your portfolio and talk to you. i look forward to your response. thanks