user8847697
user8847697

Reputation:

How to write lengthy numbers in csv without getting converted into scientific notation

I'm writing lengthy numbers as a string into a csv file. Problem is, these are notified in scientific notation.

2019100000000000 as 2.02E+15

is there a way to avoid this in Java? I'm using apache commons library to create the csv.

private String visitNumber;
public String getVisitNumber() {
    return visitNumber;
}

List<CsvRecord> records = loadData();
    for (PrivateCorporatePatientListingCsv record : records) {
        csvPrinter.printRecord(
                record.getVisitNumber()
        );
    }

Upvotes: 1

Views: 3112

Answers (2)

Arthur Va&#239;sse
Arthur Va&#239;sse

Reputation: 1571

You can specify how you want number to get converted to String using NumberFormat, and in this case, a subclass, DecimalFormat

Upvotes: 0

Joop Eggen
Joop Eggen

Reputation: 109597

Use BigInteger (integral values) or BigDecimal (fixed point) as value holding class, and not floating point, that also only approximates the value (1.2 == 1.2000 == actually 1.199999999978 or such).

BigDecimal x = new BigDecimal("2019100000000000");
String s = x.toPlainString(); // 2019100000000000

Upvotes: 1

Related Questions