浮点显示最多2个数字 [英] Float point display upto 2 number
本文介绍了浮点显示最多2个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
我有一个问题,当我得到像0.67543这样的结果时,我只希望像0.67这样的结果.表示(.)点后仅显示2个数字
这是我的代码
Hello Friends,
I have problem that when i get the result like 0.67543 i want that result like 0.67 only. means there is only 2 number show after (.) dot
here is my code
float calc = 0;
float lenght=0, breadth=0, height=0;
lenght = float.Parse(txtlenght.Text);
breadth = float.Parse(txtbreath.Text);
height = float.Parse(txtheight.Text);
calc = ((lenght * breadth * height) / 6000);
calc = Convert.ToInt32((float)Math.Round(calc, 3));
if (calc != 0)
{
lblresult.Text = "Your Volumetric Weight is : " + calc.ToString() + "Kg.";
}
推荐答案
尝试:
lblresult.Text = "Your Volumetric Weight is : " + calc.ToString("0.00") + "Kg.";
lblresult.Text ="您的体积重量为:"+ calc.ToString(" ###,###.000)+" Kg.;
lblresult.Text = "Your Volumetric Weight is : " + calc.ToString("###,###.000")+ "Kg.";
这篇关于浮点显示最多2个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文