Jaykumar Jaykumar - 1 year ago 124
Java Question

How to convert exponents in a csv file from Java

I am printing some data into a CSV file using

Apache Commns CSV
. One of the fields contains 15 digit number and is of type
. This field prints as exponential number in CSV instead of a complete number. I know
does that but is there a way in java to print it as a complete number.

I am not doing anything special. Initially I thought that
Commons CSV
will take care of it.

public void createCSV(){
inputStream = new FileInputStream("fileName");
fileWriter = new FileWriter("fileName");
csvFileFormat = CSVFormat.Excel.withHeader("header1", "header2");
csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat);

for(List<UiIntegrationDTO dto: myList>){
String csvData = dto.getPolicyNumber();

Answer Source

Prepend apostrophe

As far as I understand from the discussion in comments, it is a question about Excel interpretation of CSV file, but the file itself contains all necessary data.

I think, csvFilePrinter.PrintRecord("'" + csvData); should help. Apostrophe requires Excel to interpret a field as a string, not as a number.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download