将浮点值写入.csv文件 [英] Writing float values to .csv file

查看:69
本文介绍了将浮点值写入.csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel中的格式有一点问题我正在尝试将一些浮动值写入.csv文件,并使用Microsoft Excel进行查看.例如,我在第一行中写了6.21和12.42.然后excel将6月21日和12月46日排除在外.或者,它在124.199中占了124199.

I have a little problem with the formatting in Excel I'm trying to write some floating values into a .csv file and view it with Microsoft Excel. For example I write 6.21 and 12.42 in the first line. Then excel makes Jun 21 and Dec 46 out of it. Or it makes 124199 out of a 124.199.

[...]
    fstream f;
    f.open("test.csv", ios::out);
    for(i=0; i<world1->GetTime(); i++)
    f << Values[i][0] << ';' << Values[i][1] << endl;
    f.close();
    return 0;

}

推荐答案

它与您的代码没有任何关系-您应该修改Excel设置才能正确显示结果(好的,您可以修改您的代码,但通过Excel进行操作要简单得多.

It does not have anything to do with your code - it is the Excel settings that you should modify in order to display your results correctly (OK, you could modify your code, but it is much simpler to do it via Excel).

尝试在Excel中显示.csv文件时最常见的错误源之一是,某些语言的Excel使用逗号作为小数点分隔符,而C ++使用点.根据您的Excel版本,您可以更改默认的十进制分隔符: https://www.google.com/#q=excel+dot+ as +十进制+分隔符.

One of the most common source of errors while trying to display .csv files in Excel is the fact that Excel in some languages uses commas as decimal separators, while C++ uses dots. Depending on your Excel version, you can change your default decimal separator: https://www.google.com/#q=excel+dot+as+decimal+separator.

此外,您也可以选择所有单元格并搜索并用逗号(ctrl + H)替换点.另一种可行的方法是选择所有单元格,然后右键单击它们,选择设置单元格格式",然后选择正确的单元格格式(如果程序仍然将您的值视为日期,即使您已经做了我所做的事情,也可能会有所帮助.上面写的.)

Also, you can just select all the cells and search and replace dots with commas (ctrl + H). Another way that might work is selecting all the cells, then right-clicking them, selecting the 'Format cells' option and choosing the correct cell format (might help if the program still treats your values e.g. as dates even though you did what I have written above).

这篇关于将浮点值写入.csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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