
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.5E05" , 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.5E05") , plus the number of digits right
after the decimal point in "1.5E05" and right before the "E" (ie. this is
the substring from the "." until , and not including , the "E" in
"1.5E05") .
So in the example above , this would be 05 (or 5) + 1 (one digit after the
decimal point in "1.5E05" 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 .  
Share:

This might do what you want:
String.Format("{0:0.###################}", 0.000015) gives you "0.000015"
String.Format("{0:0.###################}", 0.0000000015) gives you
"0.0000000015"
Tom Dacon
Dacon Software Consulting
"Lior Bobrov" <a@bcd.comwrote in message
news:Ol**************@TK2MSFTNGP06.phx.gbl...
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.5E05" , 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.5E05") , plus the number of
digits right after the decimal point in "1.5E05" and right before the "E"
(ie. this is the substring from the "." until , and not including , the
"E" in "1.5E05") .
So in the example above , this would be 05 (or 5) + 1 (one digit after
the decimal point in "1.5E05" 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 .   
The following code works for me
Dim a As Double
Dim b As String
a = 0.000015
b = Convert.ToDecimal(a).ToString
This should give you the desired result.

Rgds,
Anand Mukundan http://www.dotnetindia.com
"Lior Bobrov" wrote:
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.5E05" , 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.5E05") , plus the number of digits right
after the decimal point in "1.5E05" and right before the "E" (ie. this is
the substring from the "." until , and not including , the "E" in
"1.5E05") .
So in the example above , this would be 05 (or 5) + 1 (one digit after the
decimal point in "1.5E05" 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 .
  This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by shang 
last post: by

5 posts
views
Thread by Paul Johnston 
last post: by

30 posts
views
Thread by zexpe 
last post: by

3 posts
views
Thread by Parvesh 
last post: by

12 posts
views
Thread by Frederik Vanderhaeghe 
last post: by

5 posts
views
Thread by SMichal 
last post: by

10 posts
views
Thread by Ron 
last post: by

3 posts
views
Thread by nvx 
last post: by

25 posts
views
Thread by Blasting Cap 
last post: by
          