Java String format for a long integer of at least 10 characters

I have a long integer that I want to be able to print and write to a csv file. If I just write a line that is unformatted, it will print 1.2345E9 instead of the exact full number. Which string String.format () should be used so that it correctly prints each digit.

+6
source share
3 answers

Most likely, it is MS Excel that formats things “badly” for you. Check out this test.csv file here:

 "COLUMN" 12345678901234567890 

Opened in MS Excel

enter image description here

So check out the contents of the CSV. You probably have no problem formatting Java.

+3
source

You can format the contents of the cell according to your needs, such as number / currency / date / string, etc. using the API method that you use to create csv.

0
source

To save a template for displaying numerical content from a distribution sheet to a csv file, this value must be converted to text using quotation marks.

An example :

 CSV contents (when opened in a text editor) ->: 1234567890',"""1234567890""",1234567890 XLS displays them as ------------------------>: 1234567890',"""1234567890""",1.23E+09 

The contents of each cell are displayed based on the type of the default value, which is analyzed using the Distribution application.
Therefore, for CSV there is no way besides the surrounding numeric value, with quotation marks, to preserve the desired string format.

0
source

Source: https://habr.com/ru/post/917187/


All Articles