|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
I would like to convert a string ("700") to a double (7.00) and then back to a string ("7.00"). My code is like this: double S = Convert.ToDouble("700")/100.00; string s = Convert.ToString(S); You will find that this gives the striing "7" ie it has lost all the zeros and the decimal point! Does anyone know how to retain the decimal point and zeros? thanks James |
|
#2
|
|||
|
|||
|
If it has digits in those 0s then it wouldn't have dropped them. thus 789 would become 7.89 and your problem would not exist. One way is to just test if the 0s were dropped possibly by getting length of the string before vs after, and adding the '.00' afterwards.
Not sure what you're actually doing, but if its just to divide a string by 100 seems easier to just manipulate the decimal in the string, but if its not a multiple of 10 then its not so easy. |
|
#3
|
|||
|
|||
|
try something like this...
string s = "700"; double d = Double.parse(s); d = d/ 100; s = d.ToString("0.00"); |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Convert Double to String in C# |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|