Hi ...
How to convert a variable of type Double to String , *preserving* the
original value of the Double variable , as is , in a short (convenient) way
?
For example , if there are two variables :
Dim dblResult as Double
Dim strResult as String
and dblResult = 0.000015 , then I want that strResult = "0.000015" too ;
preferably without knowing in advance how many digits come after the
decimal point .
(I took 0.000015 as an example , because this is a small number , which is
represented - after dblResult.ToString( ) - as "1.5E-05" , which does not
preserve the original value representation of 0.000015 .)
For now , I am doing this convertion (or planning to do it) using
dblResult.ToString("Fx") , where x represents the number of digits after the
decimal point , and is calculated according to what comes after the E and
the sign after it , till the end of the dblResult.ToString() result (in our
case , this is the 05 part of "1.5E-05") , plus the number of digits right
after the decimal point in "1.5E-05" and right before the "E" (ie. this is
the substring from the "." until , and not including , the "E" in
"1.5E-05") .
So in the example above , this would be 05 (or 5) + 1 (one digit after the
decimal point in "1.5E-05" and right before the "E") , which is 6 (or 06) .
This 06 is the desired precision - in our case , the conversion will be
dblResult.ToString("F06") , which should give us the desired result ,
0.000015 .
So , what I want to know is , if - and how - can I shorten this calculation
, no matter how many digits are after the decimal point , to convert the
value of original value in dblResult to String , as is .
(The purpose of this conversion from Double to String is , that I have to
display the dblResult value in a textbox) .
Thanks in advance ,
Lior .