Convert Double to String without E notation?
I am trying to convert a double to a string, but on any small enough numbers it is converting the double to an E notation first before converting that.
e.g. 0.000067492338645565634 is getting changed to 6.74923386455656E-05 when I convert to a string. I want it without the notation. I just need the leading digit and 6 precision digits, so I am just hacking everything after the first 8 characters off after conversion anyways. Is there an easy way to do this, or do I have to do something ugly like do a Split on an E and add zeroes for whatever number I have after the E?
Re: Convert Double to String without E notation?
what would 0.000067492338645565634 look like after formatting?
6.74923386 - this?
0.00006749 -this?
Re: Convert Double to String without E notation?
How do you convert it to string? If you call the ToString method of the double, you can simply pass in a format you want.
Code:
Dim d As Double = 0.000067492338645565634F
'Put as many # sign's as you may need after the decimal point in the format string
MessageBox.Show(d.ToString("#0.#######################################")
Re: Convert Double to String without E notation?
Quote:
Originally Posted by stanav
How do you convert it to string? If you call the ToString method of the double, you can simply pass in a format you want.
Code:
Dim d As Double = 0.000067492338645565634F
'Put as many # sign's as you may need after the decimal point in the format string
MessageBox.Show(d.ToString("#0.#######################################")
The "F" suffix is short for "float" forces a literal to type Single. "R" is short for "real" and forces a literal to type Double. "R" is redundant because any literal containing a decimal point is type Double by default.
Code:
Dim d As Double = 0.000067492338645565634
Console.WriteLine(d.ToString())
Console.WriteLine(d.ToString("c"))
Console.WriteLine(d.ToString("e"))
Console.WriteLine(d.ToString("f"))
Console.WriteLine(d.ToString("g"))
Console.WriteLine(d.ToString("n"))
Console.WriteLine(d.ToString("p"))
Console.WriteLine(d.ToString("r"))
Console.WriteLine(d.ToString("f6"))
Console.WriteLine(d.ToString("n6"))
Console.WriteLine(d.ToString("f15"))
Console.WriteLine(d.ToString("n15"))