Problem with ToString on a float
I have C# code that calls ToString("0.000000") on a float variable (which according to the docs means that its going to be rounded to 6 digits of precision)
I have a case where the value in the float is -14.6511173 and according to the documentation, it should be converted to either "-14.651117" or "-14.651118" (I can't tell from the docs which way negative numbers are supposed to be rounded) but the output I get is (for some reason) "-14.651120". I am on .NET 5.0. Can anyone tell me why I am seeing 20 instead of the expected 17 or 18? If I ask it for another digit in the ToString, I get "-14.6511200" instead of the expected "-14.6511173"
I have a case where the value in the float is -14.6511173 and according to the documentation, it should be converted to either "-14.651117" or "-14.651118" (I can't tell from the docs which way negative numbers are supposed to be rounded) but the output I get is (for some reason) "-14.651120". I am on .NET 5.0. Can anyone tell me why I am seeing 20 instead of the expected 17 or 18? If I ask it for another digit in the ToString, I get "-14.6511200" instead of the expected "-14.6511173"