C#数据表精度十进制

编程入门 行业动态 更新时间:2024-10-11 19:23:57
本文介绍了C#数据表精度十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下代码将新列添加到数据表:

I have this code to add new column to datatable:

DataColumn col = new DataColumn("column", typeof(decimal)); col.Caption = "Column"; mytable.Columns.Add(col);

如何为该列指定小数精度,以便该值始终采用我希望的格式?

How can I specify decimal precision for this column so the value will always be in the format I want it to be?

推荐答案

您不能。但是,当使用 String.Format 函数从表中检索值时,可以设置其格式:

You can not. However, you can format the value when you retrieve it from the table using String.Format function:

String.Format("{0:0.##}", (Decimal) myTable.Rows[rowIndex].Columns[columnIndex]);

更多推荐

C#数据表精度十进制

本文发布于:2023-11-24 19:58:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:精度   数据表   十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!