© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•5mo ago•
23 replies
Jonathan Wilson

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"
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Very strange deadlock on Exception.ToString
C#CC# / help
7mo ago
adding a double and a float
C#CC# / help
15mo ago
✅ ToString of a list of an object
C#CC# / help
3y ago