I have a requirement to convert the following types of decimal numbers to exponential format
Number 0.00001
formatted as 0.01E-04
I think you want something like:
string text = dValue.ToString("0.###E+00");
(Change the number of #
characters to change the number of decimal digits before the E.)
You can do this with a compound format specifier as well by calling string.Format
, but personally I'd use a simple one unless you need to put other text round it anyway, in which case you'd use use something like:
string text = string.Format("Before {0:0.0###E+00} After", dValue);
You'll need to use a custom format string to specify how to format your decimal:
string.Format("{0:0.##E+00}", dValue);
You can find more about custom numeric format strings on the MSDN here. There's a specific section on Exponent formats.