如何数学圆形实际数据进入asp.net标签 [英] how to math round real data get in asp.net lable

查看:49
本文介绍了如何数学圆形实际数据进入asp.net标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此计算。我希望在我的Label中获得两位小数的总计。此代码的答案没有小数点。如何解决这个问题。任何人都可以帮助我。

  //  获得价值总和 

十进制summ = 0 ;
for int n = 0 ; n < Cusinvoicegrid0.Rows.Count; ++ n)
{
summ + = Convert.ToDecimal(Cusinvoicegrid0.Rows [ n]。细胞[ 3 ]。文字);
}


十进制tott = Math.Round(summ, 2 );
Label3.Text = tott.ToString();

解决方案

十进制summ = < span class =code-digit> 0 ; 
for int n = 0 ; n < Cusinvoicegrid0.Rows.Count; ++ n)
{
summ + = Convert.ToDecimal(Cusinvoicegrid0.Rows [ n]。细胞[ 3 ]。文字);
}
summ = Convert.ToDecimal(summ.ToString( #,## 0.00; -

#,## 0.00; 0.0\" ));
Label3.Text = summ;
我知道它的工作原理不是


你真的不需要舍入。很少需要舍入,甚至可能被认为是危险的,因为如果某些舍入进入计算的中间结果,您可能会意外地失去精度。



相反,您只需要字符串格式化具有适当格式的数字数据:

http:/ /msdn.microsoft.com/en-us/library/fzeeb5cd(v=vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/dwhawy9k(v = vs.110)的.aspx [ ^ ],

http://msdn.microsoft .com / zh-cn / library / 0c899ak8(v = vs.110).aspx [ ^ ]。



-SA


I am using This Calculation.I want to get Total in two decimal point in my Label.This code answers without decimal point. how to solve this Problem.anyone can help me.

//get sum of value

    Decimal summ = 0;
    for (int n = 0; n < Cusinvoicegrid0.Rows.Count; ++n)
            {
                 summ += Convert.ToDecimal(Cusinvoicegrid0.Rows[n].Cells[3].Text);
            }
                       

          Decimal tott = Math.Round(summ,2);
          Label3.Text = tott.ToString();

解决方案

Decimal summ = 0;
for (int n = 0; n < Cusinvoicegrid0.Rows.Count; ++n)
{
     summ += Convert.ToDecimal(Cusinvoicegrid0.Rows[n].Cells[3].Text);
}
          summ =Convert.ToDecimal(summ.ToString("#,##0.00;-


#,##0.00;0.0")); Label3.Text = summ; let me know it works r not


You don't really need rounding. Rounding is rarely needed and can even be considered dangerous as you may accidentally loose precision if some rounding gets into intermediate results of calculation.

Instead, you just need string formatting of numeric data with proper formatting:
http://msdn.microsoft.com/en-us/library/fzeeb5cd(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx[^].

—SA


这篇关于如何数学圆形实际数据进入asp.net标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆