This is my code
decimal averagePrice = (decimal)dvdDS.Tables["manager"].Compute("Avg(Price)", "");
textBox3.Text = Convert.ToString(averagePrice);
I want the textbox to display "averagePrice" upto 3 decimal places.
eg I get: 6.66666666666666666
I want: 6.666
Any help would be appreciated
Thank You
I want the textbox to display "averagePrice" upto 3 decimal places.
eg I get: 6.66666666666666666
I want: 6.666
Any help would be appreciated
Thank You
Santhosh Kumar JayaramanPosted Jul 24, 2012, 9:21 AM
Jignesh TrivediPosted Jul 24, 2012, 11:44 PM
i think you can not get your required out put directly but
try
double ff = 6.6666666666666666;
double gg = Math.Floor(ff);
double newff = gg + (Math.Floor((ff - gg) * 1000) / 1000);
it gave me out put 6.666.
hope this will help you.
VulpesPosted Jul 24, 2012, 9:42 AM
textBox3.Text = (Decimal.Truncate(averagePrice * 1000m)/ 1000m).ToString("F3");
Gohil JayendrasinhPosted Jul 24, 2012, 9:29 AM
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
// max. two decimal places
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
String.Format("{0:0.##}", 123.0); // "123"
// at least two digits before decimal point
String.Format("{0:00.0}", 123.4567); // "123.5"
String.Format("{0:00.0}", 23.4567); // "23.5"
String.Format("{0:00.0}", 3.4567); // "03.5"
String.Format("{0:00.0}", -3.4567); // "-03.5"