Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
This is my code :


C#
protected void txtPresent_TextChanged(object sender, EventArgs e)
   {
       decimal conclass, pres, abs;
       decimal avg;
       conclass = Convert.ToDecimal(txtCondClass.Text.Trim());
       pres = Convert.ToDecimal(txtPresent.Text.Trim());
       abs = conclass - pres;
       txtAbs.Text = abs.ToString();
       avg = pres * 100 / conclass;
       txtAvg.Text = avg.ToString();
   }



======OUTPUT ======
Getting like this
Total = 45
Present = 29
Absent = 16
Average = 64.444444444444444444444444444
Posted
Updated 9-Oct-12 0:28am
v2

use math.round function
txtAvg.Text = Math.Round(avg.ToString(), 2);

Average = 64.44
 
Share this answer
 
Dear Friend,

do
Math.Round([Value],2)
for e.g. in your case:-

avg = Math.Round((pres * 100 / conclass),2);


Regards

Varun Sareen
 
Share this answer
 
If you need to represent only two decimal places then use:

C#
txtAvg.Text = avg.ToString("0.00");
 
Share this answer
 
v2

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