Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to convert 1222.34555566 to 1222.3455
Posted
Updated 21-Apr-11 8:44am
v2
Comments
Sergey Alexandrovich Kryukov 21-Apr-11 14:44pm    
Tags and title edited. Nothing to do with Web, this is irrelevant.
--SA
Sergey Alexandrovich Kryukov 21-Apr-11 14:45pm    
You got different answer because the goal is not fully specified.
--SA

Try this.
Math.Round(1222.34555566, 4);
 
Share this answer
 
Comments
Ankit Rajput 21-Apr-11 7:57am    
It will change the value to 1222.3456
Tarun.K.S 21-Apr-11 8:15am    
I think everyone's solution is rounded off like that!
Toniyo Jackson 21-Apr-11 8:21am    
Yeah. You are correct
Tarun.K.S 21-Apr-11 8:57am    
5d as it did help the OP!
Toniyo Jackson 21-Apr-11 8:59am    
Thanks Tarun
Use ToString method with "Fx" and replace x for the number of decimals you want:
double val = 1222.34555566;
//get 4 decimals
string txt = val.ToString("F4");
 
Share this answer
 
Try this:
String.Format("{0:0.0000}", 1222.34555566); 


...and check out this link:
http://www.csharp-examples.net/string-format-double/[^]

Good luck!
 
Share this answer
 
I want to convert 1222.34555566 to 1222.3455

What you have asked is you want to convert Six decimal place to Three and the thing that you have mentioned above is different. However considering your given thing you can Get result like this by trying below code.

MIDL
double Num = 1222.34555566;
string nNum = Num.ToString("#0.0000");
You will get nNum = 1222.3455


I hope this is what you want.
 
Share this answer
 
Comments
Toniyo Jackson 21-Apr-11 8:05am    
Did you try Gandalf? You will get 1222.3456 only :)
Gandalf_TheWhite 21-Apr-11 10:30am    
I am sorry I didn't get you!
I think you mean it will round off the value, isn't it?
If it's that then I am not sure it would round off.

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