在绑定到 DataTable 的 ASP.NET GridView 中对数字进行四舍五入的最佳方法是什么?

发布于 2024-09-14 19:37:09 字数 362 浏览 1 评论 0原文

我有一个绑定到 DataTable 的 GridView,而 DataTable 又使用 TableAdapter,如下所示:

ResultTableAdapter tableAdapter = new ResultTableAdapter();
ResultDataTable dataTable= tableAdapter.GetResult(id);
gridView.DataSource = dataTable;

该 gridview 显示许多带有数字的列。现在我必须以千为单位显示数字,保留一位小数。

例如,数据库中的数字“24753”应该在网格视图中显示为“24,8”。

最干净的实现方式是什么?

I have a GridView that is bound to a DataTable, which in turn uses a TableAdapter, like so:

ResultTableAdapter tableAdapter = new ResultTableAdapter();
ResultDataTable dataTable= tableAdapter.GetResult(id);
gridView.DataSource = dataTable;

This gridview displays many columns with numbers in them. Now I have to display the numbers in thousands with one decimal.

E.g. the number "24753" from the database should be displayed like "24,8" in the gridview.

What's the cleanest way of accomplishing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗化ㄋ丶相逢 2024-09-21 19:37:09

您可以使用“DataFormatString”属性指定自定义数字格式 - 在此 文章。我想像“#,##0,.0”这样的格式字符串应该可以满足您的需要。

You can use "DataFormatString" property to specify custom number format - check thousands number scaling using ',' in this article. I guess a format string such as "#,##0,.0" should do the trick for you.

番薯 2024-09-21 19:37:09

后来我最终更改了 GridView 的内容,因为我找不到快速且好的解决方案来显示数千个数字。但感觉不对。

I ended up changing the contents of the GridView afterwards, since I found no fast and nice solution to display the numbers in thousands. But it feels wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文