Reputation: 1191
I have a long integer that I want to be able to print out and write to a csv file. If I just write the string unformatted it prints 1.2345E9 instead of the full exact number. What String.format() should I use so that this prints out every single digit correctly.
Upvotes: 6
Views: 517
Reputation: 24002
To retain display pattern of numeric content from an spread sheet to a csv file, that value needs to be converted to text by using quotes.
Example:
CSV contents (when opened in a text editor) ->: 1234567890',"""1234567890""",1234567890
XLS displays them as ------------------------>: 1234567890',"""1234567890""",1.23E+09
Each cell's content is displayed based on the default value type as parsed by the Spread Sheet application.
Hence there is no way for CSV but surrounding a numeric value with quotes to retain desired string format.
Upvotes: 0
Reputation: 221106
This is probably just MS Excel formatting things "badly" for you. Check out this test.csv
file here:
"COLUMN"
12345678901234567890
Opened in MS Excel
So check your CSV content. Probably, you don't have a Java formatting problem there
Upvotes: 3
Reputation: 5380
You can format the cell content as per the need like number/currency/date/string etc.. by the API method you are using to create csv.
Upvotes: 0