简体   繁体   English

使用科学记数法将数据从datagridview导出到csv

[英]Export data from datagridview to csv with scientific notation

I would like to allow the user in my application to select to export data to scientific notation, but only if it is a column of doubles. 我希望允许用户在我的应用程序中选择将数据导出为科学计数法,但前提是该数据必须为双精度列。 I plan on doing a simple check: 我打算做一个简单的检查:

foreach (dataGridViewColumn col in dataGridView1.Columns
{
    if (col.GetType() == typeOf(Double)
     {
         // Perform data conversion from e.g 22.56 to scientific
     }
 }

What is the best way to do this? 做这个的最好方式是什么? String.Format? String.Format? Are there also additional checks I need to do? 我还需要做其他检查吗?

Try the string.Format indeed : 尝试string.Format确实是:

string.Format("{0:E2}", MyNumber); string.Format(“ {0:E2}”,MyNumber);

have a look at msdn Standard Numeric Format Strings for more information 有关更多信息,请查看msdn标准数字格式字符串

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

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