[英]Number with more than 15 digits converts to 0 while writing to CSV file
I have to prepare a string with data and commas. 我必须准备一个包含数据和逗号的字符串。 Then write that string to a csv file using
java.util.zip.ZipEntry.
然后使用
java.util.zip.ZipEntry.
将该字符串写入csv文件java.util.zip.ZipEntry.
Now the problem is: it works fine for the number which are less than or equal to 15 in length. 现在的问题是:对于长度小于或等于15的数字,它可以正常工作。
For numeric data more than 15 digits long gets converted to 0. 对于长度超过15位的数字数据,将转换为0。
So I tried by using enclosing numeric data between double quotes for converting numeric data to string to avoid that issue. 因此,我尝试通过在双引号之间使用数字数据将数字数据转换为字符串来避免该问题。 But that is not working.
但这是行不通的。
ZipEntry ze = new ZipEntry("my.csv");
ByteArrayOutputStream ba = new ByteArrayOutputStream();
ZipOutputStream zo = new ZipOutputStream(ba);
zo.putNextEntry(ze);
String csv = "123456789012345,12345678901234567890,\"hello\",";
zo.write(csv.getBytes());
zo.closeEntry();
can anyone suggest something on this? 有人可以对此提出建议吗?
Just a guess: you are opening the generated csv in MS Excel. 只是一个猜测:您正在MS Excel中打开生成的csv。
Use a text editor to check the file. 使用文本编辑器检查文件。
There is a bug report which says: "Last digits are changed to zeroes when you type long numbers in cells of Excel" 有一个错误报告,其中指出: “当您在Excel单元格中键入长数字时,最后一位将变为零”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.