POI reading decimals


I have an excel *.xlsx with a cell of type Número , the value I have in the excel is 0,0794497914814776 but the value returned by the method celda.getNumericCellValue() is: 0,07944979148147759987

I have tried to convert the cell into text before reading it, but it throws an exception:

String a = celda.getStringCellValue();

This I show was useful to read another excel, with a custom cell format.

The main problem I have is that the cell can contain 5, 10 or 15 decimals and we need to respect the value that comes in the excel.

Can you read the exact value of the cell?

asked by nachfren 07.06.2018 в 12:17

1 answer


It's a floating-point handling problem, which happens in any programming language, I'll give you an example in Java:

const valor1 = .0794497914814776;
const valor2 = .07944979148147759987;

console.log ('La diferencia entre',valor1,'y', valor2,'es', valor1 - valor2);

To transform text you can try NumberToTextConverter , a class created to do precisely what you try.

answered by 07.06.2018 / 12:31