2

The output of the code below changed from "2.0" in .NET 4.7.2 to "1.9" in Core 3.1

Console.WriteLine((1.95).ToString("N1"));

I think this may be related to https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/ but I dont understand which of the floating point formatting changes is causing this difference. What change in .net core 3.1 caused this? Thanks.

innominate227
  • 11,109
  • 1
  • 17
  • 20
  • 1
    can't answer the question but I find it interesting that if you set a variable of type double (or float) to 1.95f and do the same with it you get 2.0 which is the value I would expect to get for N1. This (1.95f).ToString("N1") will also give you 2.0 - note the f after 1.95. It is something in how it is interpreting the constant I believe and not necessarily the formatting. – Scott Mildenberger Dec 02 '22 at 22:22
  • 1
    I was using .Net 6 but it duplicates what you see in Core 3.1 - value of 1.9 – Scott Mildenberger Dec 02 '22 at 22:30
  • @ScottMildenberger that's just causesed by differences in what numbers you can represent with a float or double. https://dotnetfiddle.net/jsFbNu – innominate227 Dec 08 '22 at 16:38

0 Answers0