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.ToStr ing( ) - 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.ToStr ing("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.ToStr ing() 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.ToStr ing("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 . 2 4625
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.00000000 15"
Tom Dacon
Dacon Software Consulting
"Lior Bobrov" <a@bcd.comwro te in message
news:Ol******** ******@TK2MSFTN GP06.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.ToStr ing( ) - 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.ToStr ing("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.ToStr ing() 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.ToStr ing("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.ToDecim al(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.ToStr ing( ) - 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.ToStr ing("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.ToStr ing() 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.ToStr ing("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 thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: shang |
last post by:
Hi!
I am trying to find a function that converts a string into a double
or a long double number. I found atod() but I don't know which library
I have to include to use it. Could someone help me?
Thanks!
|
by: Paul Johnston |
last post by:
Hi Just started using c# to do a task I usually use Perl to do and hit
a limit in my knowledge :-)
I have a program which reads from a large text file, extracts certain
lines then gets a string from these lines.
Question
If the object I extract is in the form of a number how can I cast it
into a number so I can prerform mathematical...
|
by: zexpe |
last post by:
I have an extremely cpu/data intensive piece of code that makes heavy
use of the following function:
void convertToDouble(const std::string& in, double& out)
{
out = atof(in.c_str());
}
I would really like to get away from using any old C-style functions.
So, I modified the above function to make it follow the C++ convention:
|
by: Parvesh |
last post by:
hi,
I am using a webservice which Returns the Result in an XML string,
The XML response i get i svery cumbersome to parse,
But if i could convert it to the Corresponding Class using the
System.Xml.Serialization, i think that can solve my problem.
But i tried using the Deserialize method for converting the XML to the
Corresponding Object,...
|
by: Frederik Vanderhaeghe |
last post by:
Hi,
I have a problem converting text to a double. Why doesn't the code work:
If Not (txtdocbedrag.Text = "") Then
Select Case ddlBedrag.SelectedIndex
Case 0
Case 1
| |
by: SMichal |
last post by:
Hi, how can I parse string "? 20.000" to double ?
|
by: Ron |
last post by:
I want to calculate the surface area of a sphere from an inputed radius
with option strict on. I guess I am not converting something
correctly.
Here is what I am doing:
I have a textbox txtradius that I enter a radius into.
I then have a lable that I want the surface area to be displayed in
called lblsurface
|
by: nvx |
last post by:
Hi,
I'm looking for a simple way to convert a Double to a String exactly
the .ToString() does, except these two differences:
- the number of decimals is given (rounding is applied if
necessary), and
- trailing zeroes are kept.
This means I need it to be converted using the scientific notation if
the number is greater than a certain value...
|
by: Blasting Cap |
last post by:
I keep getting errors that pop up when I am trying to convert an
application from dotnet framework 1.1 to framework 2.0. The old project
was saved in sourcesafe from Visual Studio 2003, and I have opened it in
Visual Studio 2005.
I've cleared up most errors, but have one that beats the heck out of me.
I have a page:
sales/Item.aspx...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |