Reputation: 17388
I have this simplified method:
private string GetStringValue(object Value)
{
return ((double)Value).ToString();
}
which spews out:
1.8E-09
I intend to get this format though:
1.8e-009
Is this easily achievable?
Upvotes: 0
Views: 105
Reputation: 1499770
Looking at the documentation for custom numeric format strings, I think you want:
// Separate variable just for clarity
double number = (double) Value;
return number.ToString("0.###e+000");
(Use 0.###E-000
if you only want the symbol for negative exponents.)
Upvotes: 6
Reputation: 1808
You need to use String.Format and use the right format string.
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
This should help with decimal format strings.
So
(double)Value.ToString("E")
would do it for en-US.
Upvotes: 1