Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After calculation result value is like "5.245896654556" show in textbox i want the value in textbox is like 5.25 in C# windows application
Posted
Updated 23-Jul-13 1:25am
v2

Hi,

Try:
C#
yourTextBox.Text = Math.Round(yourDouble, 2).ToString();

More about the Math.Round (Double, Int32) method:
http://msdn.microsoft.com/en-us/library/75ks3aby.aspx[^]

Hope this helps.
 
Share this answer
 
v2
Do code like..
C#
textbox1.Text = Math.Round(double.Parse(textbox1.Text),2).ToString();

But,you should be aware to know that, Math.Round uses "banker's rounding" method by default, which you might not want.I show some alternative to you below.

Or,
Alternatively use..
C#
yourDecimalNumber.ToString("N");

Or,
Use..
C#
String.Format("{0:0.00}", 5.245896654556);      // "5.25"

Or
,
C#
var roundedInput = yourDecimalNumber.ToString("0.00");
 
Share this answer
 
v5

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