I am trying to convert a float to a string without getting a scientific style (1.13E-8).
I am looking for some combination of the "F" and "R" qualifiers. I want F not to use scientific style, but I also want R to use as little space as possible to represent the number exactly.
So, given 0.000000001, the line should be 0.000000001. Not 1E-09, not 0.000000001000.
Is it possible to tell the system to "make it a fixed point, but use the minimum digits necessary to indicate the exact number"?
If not, what would be a good workaround? I thought: use precision of 20, and then just crack the end of 0, if any. in line. Anything better?
Edit:
Here is the version I'm using. I really hoped there would be a format specifier that I could use to do this instead.
var s = f.ToString("F20");
if (s.Contains("."))
{
s = s.TrimEnd('0').TrimEnd('.');
}
source
share