Click here to Skip to main content
16,006,065 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear all,

I have a value in double like 1.0;

Now I'm trying to convert it into string ... Here i need the same 1.0 in string... Instead 1.0 i'm getting 1... Please help me.. Thanks in advance :-)

double value = 1.0;
string strvalue = Convert.ToString(value);

Here I'm getting strvalue as 1

but i need to get 1.0 once after converting to string...

Help me ..
Posted
Comments
[no name] 9-Jul-13 11:35am    
Use ToString() on value and use format specifiers to get the string format you want. Or use String.Format() to accomplish the same thing.

double value = 1.0;
string strvalue = String.Format({0: 0.0#####}, value));
 
Share this answer
 
Try:

double value = 1.0;
string strvalue = value.ToString("f1");
 
Share this answer
 
v2
Try:
C#
double value = 1.0;
string s = value.ToString("0.0");
 
Share this answer
 
Hi,

Have a look here:
http://stackoverflow.com/a/8039032[^]
So, try:
C#
string strvalue = value.ToString(".0###############");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900