Format string for fixed length real value in scientific representation?
-
Hi! I'm looking for a format string (to String.Format()) which is capable of handling the following criterias: My input is a real value like -0.00123456 or 1233456.134 etc. I want the output in scientific representation like "-1.234560E-003". I want the output string to ALWAYS be 14 chars long no matter what. How does the correct format string to accomplish this look like? I've tried "{0:E7}" for positive values and "{0:E6}" for negative values. But this doesn't cover values greater than 9.9999999E+999 and values less than 1.0E-999.
-
Hi! I'm looking for a format string (to String.Format()) which is capable of handling the following criterias: My input is a real value like -0.00123456 or 1233456.134 etc. I want the output in scientific representation like "-1.234560E-003". I want the output string to ALWAYS be 14 chars long no matter what. How does the correct format string to accomplish this look like? I've tried "{0:E7}" for positive values and "{0:E6}" for negative values. But this doesn't cover values greater than 9.9999999E+999 and values less than 1.0E-999.
I suspect that means you need a great level of accuracy than C# offers. Are you using the floats, Decimals or doubles ? You may need a scientific library of some sort.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
I suspect that means you need a great level of accuracy than C# offers. Are you using the floats, Decimals or doubles ? You may need a scientific library of some sort.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Well, the probability that I get values less than E-999 or greater than E+999 is more or less zero, but I thought that it would be cleaner if I could handle both positive and negative values with one format string. I use doubles, but thats not carved in stone...