如何删除小数后的分数 [英] How do I remove fraction after decimal

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

问题描述





我想从我的数据表中删除分数。



例如:



我有下表:



A 98.581253

B 7.105125

C 101.325836



我希望以下列格式在datagridview中显示:



A 98.58

B 7.11

C 101.32

Hi,

I would like to remove fraction from my data table.

for example:

I have a following table:

A 98.581253
B 7.105125
C 101.325836

and I would like to show in datagridview in the following format:

A 98.58
B 7.11
C 101.32

推荐答案

如果你想格式化您可以使用方法的值.toString(0.00)
If you want a formatting of the values the you can use the method .toString("0.00")


从数据库中读取数据后,您应该使用 Decimal.Round() - 如果您使用小数值或 Math.Round()获取双值。
After reading the data from database, you should use Decimal.Round()- if you are using decimal values or Math.Round() for double values.


for (int x = 0; x < dtform.Rows.Count; x++)
            {
                decimal sub = decimal.Parse(dtform.Rows[x][3].ToString());


                DGV1.Rows[x].Cells["A"].Value = decimal.Round(sub,2);
            }


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

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