Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to transform a double get it from a slider with format "xx.xxxx" into a double with next format "xxxxxx.xx".


Example if receive: 15.678934 I want to convet it in: 156789.34
I checked in several places but I only find formulas to round or add ceros before or after like

C#
mydouble.ToString("######.##", CultureInfo.InvariantCulture) );


mydouble.ToString("0000:00.00", CultureInfo.InvariantCulture) );


Also I checked the starndart and custom string formats but apparently nothing fits with my objetive: http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^]

Any help please ?
Posted
Updated 30-Nov-14 21:58pm
v2
Comments
Andreas Gieriet 28-Nov-14 10:13am    
What do you mean by "double"?
Is it a string containing these forms of number or is it a variable of type double?
Regards
Andi
Kinna-10626331 28-Nov-14 10:32am    
It is a variable type double

Try this:
C#
double d = 12.345678;
Console.WriteLine("{0,8:000000.00}", d);
Console.WriteLine("{0}", d.ToString("000000.00"));
 
Share this answer
 
Comments
Andreas Gieriet 28-Nov-14 10:18am    
My 5 (assuming "mydouble" in the question is of type "double")!
Cheers
Andi
OriginalGriff 28-Nov-14 10:24am    
It seems like a good assumption! :laugh:
Andreas Gieriet 28-Nov-14 11:04am    
For some reason it looks like my 5 is not taken by CP...(?).
Will see if this is a temporal issue only (or only on my PC?).
Cheers
Andi
OriginalGriff 28-Nov-14 11:10am    
Caching, probably - the rep history shows an upvote at 04:02pm
So it's at the hamsters end!
Kinna-10626331 28-Nov-14 10:35am    
if mydouble = 15.163179916317993 , then using your solutions retuns {0.8:000.015,16}
I don't know what I was thinking ! Lately I had to do many parsing and conversions stuff that I didn't realize that for this case the solution were simple maths!!

C#
double dconverted=mydouble*10000; 
d.tostring("######.##");
 
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