473,395 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to convert a double 2.0 to string "2.0"

Hi, guys,

If I simply do a double d = 2.0 ,and then s=d.ToString() , it will trim
the .0 off and return me 2, is there a good way to keep .0 and return me
2.0.

Thanks,
Nov 17 '05 #1
2 1840
Use the formatting optin in the ToString() method:

double d1 = 2.0;
double d2 = 2.01;

Trace.WriteLine( d1.ToString("#,###.0") );
Trace.WriteLine( d1.ToString("#,###.00") );
Trace.WriteLine( d2.ToString("#,###.0") );
Trace.WriteLine( d2.ToString("#,###.00") );
Trace.WriteLine( d2.ToString("#,###.000") );

Nov 17 '05 #2
The ToString method is overloaded and accepts parameters to specify the
format. For example ToString("#.0")

See the docs.

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Jianwei Sun" <js***********@gmail.com> escribió en el mensaje
news:uw**************@TK2MSFTNGP14.phx.gbl...
Hi, guys,

If I simply do a double d = 2.0 ,and then s=d.ToString() , it will trim
the .0 off and return me 2, is there a good way to keep .0 and return me
2.0.

Thanks,

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
7
by: Jim Bancroft | last post by:
Hi everyone, A basic one here, I think. I haven't found the pattern yet, but sometimes when I cast a variable to another type using the "C" style cast operator the compiler refuses to play...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
4
by: michi | last post by:
Hello How can I convert a string to double with a decimal point as seperator? ***CODE**** strNumber ="12.00" dblDouble = Cdbl(strNumber) ****
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
6
by: Dennis | last post by:
Is there anything built in to vb.net that will take a plain text string and reformat it as HTML? What I mean is: o replace newlines with <BR> o replace " with &quot; o etc. I am using vb.net...
6
by: nadeaupn | last post by:
Trying to convert "1.12" to double : Dim MyDouble as double MyDouble = cdbl("1.2") I obtain the following error message : "La conversion de la chaîne "1.2" en type 'Double' n'est pas...
1
by: niharnayak2003 | last post by:
Hi All, I am facing the problem in Typecast inside the Generic class. I need a function which will take two param 1:-Xpath 2:- XMLDOC and return me what i will need. here is the code for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.