I'm trying to read the following value from an Excel file cell:
19,000,000.00
19,000,000.10
19,000,000.01
19,000,000.101
What I see in the Excel file are also those values.
However, my output respectively, when using cell.getNumericValue()
:
1.9E+7
19,000,000.1
19,000,000.01
19,000,000.101
The conversion to the exponential values makes it hard to manipulate and obtain all the information I need from the value, because when calling the .scale()
and .precision()
methods, the value is completely off. (the exponential value in question gives me precision: 2; scale: -6 )
How do I make it so that I get what I see instead of the conversion? My end-goal, basically, is to ensure the length of the value does not exceed my settings (eg. Numeric(15, 3) )
I've tried:
Double.parseDouble()
BigDecimal.valueOf().doubleValue()
BigDecimal.valueOf().floatValue()
But everything keeps returning me back the exponential value.
Edit
Due to request, portion of the code I'm doing, modified as to not show the whole thing and clutter:
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
Object theObject = new Object();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext() && !hasError) {
Cell cell = cellIterator.next();
theColumnIndex = cell.getColumnIndex();
(switch statement omitted)
numericValue = cell.getNumericCellValue();
//numericValue will return values like 1.9E+7, 19000000.10
// 19000000.01, 19000000.101
// afaik, the return type is Double
theObject.setAmount( BigDecimal.valueOf(numericValue) );
//SetAmount function expects a BigDecimal input, hence the use
/*
Additional checking for length and precision here to try and catch and
log it. Put after and not before because so long as it's a valid value (ie.
not String), it should still go in.
*/
}