十进制舍入文本框中的值 [英] Decimal round off value in textbox

查看:78
本文介绍了十进制舍入文本框中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计算结果值就像5.245896654556在文本框中显示我希望文本框中的值类似于5.25在C#windows应用程序

After calculation result value is like "5.245896654556" show in textbox i want the value in textbox is like 5.25 in C# windows application

推荐答案





尝试:

Hi,

Try:
yourTextBox.Text = Math.Round(yourDouble, 2).ToString();



更多关于 Math.Round(Double,Int32) )方法:

http:// msdn。 microsoft.com/en-us/library/75ks3aby.aspx [ ^ ]



希望这会有所帮助。


More about the Math.Round (Double, Int32) method:
http://msdn.microsoft.com/en-us/library/75ks3aby.aspx[^]

Hope this helps.


代码如..

Do code like..
textbox1.Text = Math.Round(double.Parse(textbox1.Text),2).ToString();



但是,你应该知道, Math.Round 使用默认情况下,银行家的舍入方法,你可能不需要。我在下面给你一些替代方案。



或者

或者使用..


But,you should be aware to know that, Math.Round uses "banker's rounding" method by default, which you might not want.I show some alternative to you below.

Or,
Alternatively use..

yourDecimalNumber.ToString("N");





使用..


Or,
Use..

String.Format("{0:0.00}", 5.245896654556);      // "5.25"






Or
,

var roundedInput = yourDecimalNumber.ToString("0.00");


这篇关于十进制舍入文本框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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