Reputation:
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
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
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