简体   繁体   English

千位分隔符无法正常工作

[英]Thousand separator not working right way

I want to display 200000 as 200.000, by set DefaultCellStyle 我想通过设置DefaultCellStyle将200000显示为200.000

dgrTonKho.Columns["xtkTTN"].DefaultCellStyle.Format = "0,.###";

but when dispay it just like 200, all zero after the separator has been removed, I don't know why 但是当它像200一样支付时,除去分隔符后全为零,我不知道为什么

Try this: 尝试这个:

dgrTonKho.Columns["xtkTTN"].DefaultCellStyle.Format = "#,0.###";

From MSDN: 从MSDN:

Thousand separator specifier: If one or more ',' characters is specified between two digit placeholders (0 or #) that format the integral digits of a number, a group separator character is inserted between each number group in the integral part of the output. 千位分隔符:如果在用于格式化数字整数的两位数字占位符(0或#)之间指定了一个或多个','字符,则在输出的整数部分的每个数字组之间插入一个组分隔符。

Thousand separator must be between two digit placeholders 千位分隔符必须位于两位数的占位符之间

You can dynamically parse the cellvalue 您可以动态解析单元格值

 this.dgrTonKho.CellFormatting += new DataGridViewCellFormattingEventHandler(dgrTonKho_CellFormatting);

add cellformatting event and try to parse the cell value dynamically it will do the job 添加cellformatting事件并尝试动态解析单元格值,它将完成工作

 void dgrTonKho_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != this.dgrTonKho.NewRowIndex)
            {
                double d = double.Parse(e.Value.ToString());
                e.Value = d.ToString("0.00##");
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM