格式化数据表中包含的值 [英] Formatting the values contained in datatable

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

问题描述

我有一个数据表,其中一个列的值假定为"25.00",如何将其转换为"25".
我已经尝试了一些方法,但是没有成功.可能是愚蠢的错误,请帮助
注意:我无法更改当前的数据类型.我已经从我那里获取了数据表.

I have a datatable which has a value suppose ''25.00'' in one of its column , how can I convert it to ''25''.
I have tried somethings out but it didn''t worked out. might be silly mistake please help
Note: I cannot change the datatype present. I have the datatable fetched with me.

推荐答案

如果无法将数据类型更改为十进制(这将是首选解决方案),则可以从中获取字符串数据.行,然后使用 Decimal.TryParse方法 [ Decimal.ToString方法将其设置为自己喜欢的格式(字符串) [^ ].

注意:请注意小数点分隔符.如果数据来自其他区域性,则可能必须用当前区域性十进制分隔符替换数据中使用的十进制分隔符
If you cannot change the data type to decimal (which would be the preferred solution), you can fetch the string data from a row and then use Decimal.TryParse Method[^].

Now you would have an actual number in your hand and then format it as you like for example using Decimal.ToString Method (String)[^].

Noet: Watch out the decimal separator. If the data is from different culture, you may have to replace the decimal separator used in the data with current cultures decimal separator


这篇关于格式化数据表中包含的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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