限制小数位数 [英] Limiting the decimal Places

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

问题描述

有没有办法将小数位数限制为2? 

Is there a way to limit the decimal places to just 2? 

/*Set the variable to 0 */
_bmiVal = 0;
/*Equation*/
_bmiVal = (_weight / Math.Pow(_inchesVal + _heightVal * 12, 
2)) * 703;
/*Place the answer in the WPF text box as a string*/
txtBMI.Text = _bmiVal.ToString();

推荐答案

您好,

尝试以下

<TextBox Text="{Binding Value, StringFormat=N2}" />
<TextBox Text="{Binding Value, StringFormat={}{0:#,#.00}}" />


https://stackoverflow.com/questions/18361689/how-to-format-number-of-decimal-places-in-wpf-using-style-template

https://stackoverflow.com/questions/18361689/how-to-format-number-of-decimal-places-in-wpf-using-style-template


这篇关于限制小数位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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