写长号给csv [英] Writing long numbers to csv

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

问题描述

嘿,

所以我正在尝试将长数写入csv,例如。

43564765876978
56576867897699
45765879789789

但这些仍然被4.575769E + 12等值所取代,我假设它是因为csv是使列成为一个数字列,它太大了?
我该如何解决这个问题?
注意:当数字数大于12位数时,它会变成丑陋的科学记数法格式。

非常感谢。





我尝试了什么:



我试图在字符串中转换数字并生成csv但仍然是同样的问题。

解决方案

我坚信< a href =https://www.codeproject.com/script/Membership/View.aspx?mid=11398>UrošŠmon [ ^ ]对于这句话是对的: Csv是非常简单的文本格式,即对其内容一无所知 。您没有提供将数字保存到csv文件的方法,因此我们无法帮助您解决问题,因为我们无法访问您的屏幕或数据。我测试了下面的代码并且它工作得很完美,即使Excel以科学格式显示数字。



  decimal  [] numbers = { 43564765876978  56576867897699  45765879789789 }; 
string path = @ D:\\ \\text.csv;

string [] lines = numbers.Select(x => x.ToString())。ToArray();

File.WriteAllLines(path,lines);

lines = File.ReadAllLines(path);
// 结果:
// 43564765876978
// 56576867897699
// 45765879789789


引用:

但是这些仍然会被诸如4.575769E + 12


这不是csv相关的问题,如果你输出到屏幕,你会看到完全相同的值。

这是写入csv的程序是有罪的。

输出存储数据的数字或数据类型时可以是格式化。

但是只要我们看不到你的代码,就很难说出来。 / blockquote>

问题不在csv端。 Csv是一种非常简单的文本格式,对其内容一无所知。看起来您正在使用默认格式将浮点数写入其中。使用写入时带小数位零的格式,或将数字转换为整数


Hey,

So I'm trying to write long numbers to a csv eg.

43564765876978
56576867897699
45765879789789

But these keep getting replaced with values such as 4.575769E+12, I'm assuming its because the csv is making the column a number column and its too big? 
How can I fix this? 
Note: it's get Ugly scientific notation format when digit number count greater then 12 number digit.

Many thanks.



What I have tried:

I have tried to convert number in string and generate csv but still same issue.

解决方案

I strongly believe that Uroš Šmon[^] is right as to this statement: "Csv is very simple text format, that knows nothing about its content". You did not provide a way you save numbers into csv file, so we can't help you to resolve your issue, because we have no access to your screen or data. I tested below code and it works perfect, even if Excel displays the numbers in scientic format.

decimal[] numbers = {43564765876978, 56576867897699, 45765879789789};
string path = @"D:\text.csv";

string[] lines = numbers.Select(x=>x.ToString()).ToArray();

File.WriteAllLines(path, lines);

lines = File.ReadAllLines(path);
//result:
//43564765876978 
//56576867897699 
//45765879789789 


Quote:

But these keep getting replaced with values such as 4.575769E+12


This not a csv related problem, if you output to screen, you will see the exact same values.
It is the program that write to csv that is guilty.
It can be the formatting when you output the numbers or the datatype that store the data.
But as long as we don't see your code, it is difficult to tell.


Problem is not on csv side. Csv is very simple text format, that knows nothing about its content. It looks like you are writing floating point numbers into it, using default format. Use format with zero decimal places on write, or convert numbers to integer


这篇关于写长号给csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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