本文介绍了计算平均百分比,但小数点后的位数超过2位,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:


This is my code :


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();
   }




======输出======
变得像这样
总计= 45
目前= 29
缺席= 16
平均值= 64.444444444444444444444444444




======OUTPUT ======
Getting like this
Total = 45
Present = 29
Absent = 16
Average = 64.444444444444444444444444444

推荐答案

txtAvg.Text = Math.Round(avg.ToString(), 2);


平均值= 64.44


Average = 64.44


Math.Round([Value],2)

例如您的情况:-

for e.g. in your case:-

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



问候

Varun Sareen



Regards

Varun Sareen


txtAvg.Text = avg.ToString("0.00");


这篇关于计算平均百分比,但小数点后的位数超过2位,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:03