Start Debugging

dotnet-11

328 posts · Page 1 of 33

Why does a C# decimal keep trailing zeros, and how do I remove them?

1.10m prints "1.10" because System.Decimal stores a scale alongside its digits, and arithmetic, parsing, and JSON all preserve it. How the scale is chosen, why 1.1m == 1.10m but their strings differ, three ways to strip trailing zeros (G29, a 0.## pattern, dividing by 1.000...m) and the 1E-05 trap in G29, how to force a fixed scale, and why .NET 11's double to decimal change produces digits no trick removes. Verified on .NET 10.0.14 and .NET 11 RC3.

How to mark a controller action's response as nullable in ASP.NET Core's built-in OpenAPI document

Microsoft.AspNetCore.OpenApi only marks a response nullable when the action returns a bare T? (and, on .NET 10, not even Task<T?>). ActionResult<T?> and IActionResult lose the annotation on both .NET 10 and .NET 11 RC2. Here is why, a tested operation transformer that fixes it, and the 204 No Content trap that makes the spec lie unless you also change MVC's formatter.
Next