Single/Double.ToString() help
-
i cannot for the life of me figure out how to get this to return a string that is not formatted in scientific notation is there a simple guide or set of examples somewhere on how to use IFormatProvider? msdn doesn't seem to provide any examples edit: i found an example, it uses a mask... but why does the msdn page mention special characters (d/c/etc) for formating? where can i find a reference for the available masks?
-
i cannot for the life of me figure out how to get this to return a string that is not formatted in scientific notation is there a simple guide or set of examples somewhere on how to use IFormatProvider? msdn doesn't seem to provide any examples edit: i found an example, it uses a mask... but why does the msdn page mention special characters (d/c/etc) for formating? where can i find a reference for the available masks?
This is a link to really good site on how to format numbers: http://authors.aspalliance.com/aspxtreme/aspnet/types/numericformatstrings.aspx
-
i cannot for the life of me figure out how to get this to return a string that is not formatted in scientific notation is there a simple guide or set of examples somewhere on how to use IFormatProvider? msdn doesn't seem to provide any examples edit: i found an example, it uses a mask... but why does the msdn page mention special characters (d/c/etc) for formating? where can i find a reference for the available masks?
You keep reading the wrong things. Did you try reading the documentation for the
NumberFormatInfo
, which implementsIFormatProvider
? You don't even need to specify this for numeric types instring.Format
(or any other formatting method likeConsole.WriteLine
). There's also a big section on formatting in the .NET Framework SDK, which should be your first stop for .NET-related documentation, articles, and examples. There is a simple solution for the scientific notation:string s = string.Format("{0:e}", myNum);
// OR
s = myNum.ToString("e"); // Also documented in numeric type's ToString docsMicrosoft MVP, Visual C# My Articles