我在C#输入格式中遇到问题。 [英] I am facing problem in C# input format.

查看:68
本文介绍了我在C#输入格式中遇到问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个函数来计算C#中datagridview中的指定列的总和。

它工作在开始时查找。但现在我面临错误输入字符串格式不正确。我检查过但无法找到我所犯的错误。

这里是我的代码

I wrote one function to caiculate the sum of specifix columns in datagridview in C#.
It Worked find at begining. but now I am Facing error "Input String is not in a correct format". I checked but unable to find mistake where i did.
here is my code

public void totalsum()
       {
           int i = 0;
           double j = 0.00;


           for (i = 0; i < dataGridView1.Rows.Count; ++i)
           {


               j += Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value);

               MessageBox.Show(j.ToString());
           }
           txtitmtotal.Text = j.ToString("c");

       }





我的尝试:



我试图找出我做错的错误。但无法跟踪。



What I have tried:

I tried to findout mistake what i did. but unable to trace.

推荐答案

使用调试器查看单元格中的确切内容,并检查它是否为数字 - 因为错误是告诉你:这个值不能转换为双精度值。



我们不能为你做这个,我们没有任何访问权限数据。
Use the debugger to look at exactly what is in the cell, and check that it is a number - because that is what the error is telling you: this value can't be converted to a double precision value.

We can't do that for you, we don't have any access to your data.


请尝试下面的代码希望它能为你工作

Please try below code hope it will work for you
public void totalsum()
        {
            int i = 0;
            decimal j = 0.00;
            
 
            for (i = 0; i < dataGridView1.Rows.Count; ++i)
            {
               
 
                j += Convert.ToDecimal(dataGridView1.Rows[i].Cells[5].Value);
                
                MessageBox.Show(j.ToString());
            }
            txtitmtotal.Text = j.ToString("C", LocalFormat);
            
        }


这篇关于我在C#输入格式中遇到问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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