开发者

formatting decimal value in column in datagridview

开发者 https://www.devze.com 2023-04-12 06:48 出处:网络
I want to formatting a column of sum value: for example I have 19240 I want it 192.40 I tried many way but nothing

I want to formatting a column of sum value: for example I have 19240 I want it 192.40 I tried many way but nothing

dgw.Grid.Columns["Sum"].DefaultCellStyle.Format="0:00" // 192:40

dgw.Grid.Columns["Sum"].DefaultCellStyle.Format="n"    // 19240.00

dgw.Grid.Columns["Sum"].DefaultCellStyle.Format="0.00" // 19240.00

dgw.Grid.Columns["Sum"].DefaultCellStyle.Format=string.Format("{0:0.##}") // Exception

I want all items in that column in datagrid view with the same format

edit : a way to do it:

I use this methode to get what I want

    int 开发者_开发百科_sum;
    public int Sum
    {
        get { return _sum; }
        set { _sum= value; }
    }

    public double SumAsdouble
    {
        get
        {
            if (_sum== 0)
                return 0;
            else
                return Convert.ToDouble(_sum) / 100;

        }
    }

and I make hidden the Sum and show the SumAsdouble

and this work for me


What is the value in the cell?

It looks like it is 19240, which means that formatting it to 2DP will return 19240.00, as you are seeing. If you want 192.40, then you'll need to divide by 100 first - you'll not be able to do this with string formats.


I assume that you always want to have the last two digits to be decimal digits and that your number is always five digits long. Then you can use "000.00" or "%" as format string. Alternatively, you can devide your number by 100.

0

精彩评论

暂无评论...
验证码 换一张
取 消