如何将两个精度的float值赋给textboox [英] how to assign float value with two precision to textboox
本文介绍了如何将两个精度的float值赋给textboox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有返回浮动的触发器
100.00
当我指定这个浮动到文本框,它只显示100没有十进制数。
Hi,
I have a proc with return a float as
100.00
when i assign this float to textbox ,it is showing only 100 without decimal number.
txtTotalPurCost.Text = float.Parse(objdto[0].Tot_Pur_Cost.ToString().TrimStart().TrimEnd());
推荐答案
尝试:
Try:
txtTotalPurCost.Text = float.Parse(objdto[0].Tot_Pur_Cost.ToString().Trim()).ToString("0.##");
格式字符串表示始终显示小数点后两位。
The format string says to always show two decimal places.
你可以使用自定义数字表格,比如
但这会在你尝试0.00空字符串时给出。
Ex:
you can use the Custom numeric formts like
but this will give when you try 0.00 empty string.
Ex :
Float I= 100.00
string str=I.ToString ("#.##");
您的:
Your one:
txtTotalPurCost.Text = float.Parse(objdto[0].Tot_Pur_Cost.ToString ("#.##");
.TrimStart().TrimEnd());
更多信息
http://msdn.microsoft.com/en -us / library / 0c899ak8(v = vs.110).aspx [ ^ ]
decimal d = 1.000M;
string s = d.ToString("#.##");
txt1.Text = s;
这篇关于如何将两个精度的float值赋给textboox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文