You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Mani <ma...@gmail.com> on 2012/10/18 17:09:48 UTC

Decimal number is fetched wrong when i use Event model and sax parser

Hi,

For memory problem, i am using EventModel and sax parser to read the data from
the Excel. I have used the XLSX2CSV.java example given the apache site. While
reading the decimal number,it is not fetched as it in the Excel Sheet.
For eg, the value in the excel cell is 9.32226879. After reading through the sax
parser, i am getting it as 9.3222687900000007. Is there any way i can fetch the
decimal number as it is in Excel.

But this is not happening all the time. I have given 11.3698 in the excel and
the same is fetched.



Thanks,
Mani


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Decimal number is fetched wrong when i use Event model and sax parser

Posted by manivel <ma...@gmail.com>.
Hi Nick,

My problem is solved by using following code.

BigDecimal.valueOf(Double.parseDouble(n)).toPlainString();

where n is the decimal value fetched through SAX parser.


Thanks a lot in helping.



-Mani



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Decimal-number-is-fetched-wrong-when-i-use-Event-model-and-sax-parser-tp5711229p5711295.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Decimal number is fetched wrong when i use Event model and sax parser

Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 18 Oct 2012, Mani wrote:
> For memory problem, i am using EventModel and sax parser to read the 
> data from the Excel. I have used the XLSX2CSV.java example given the 
> apache site. While reading the decimal number,it is not fetched as it in 
> the Excel Sheet. For eg, the value in the excel cell is 9.32226879. 
> After reading through the sax parser, i am getting it as 
> 9.3222687900000007.

http://en.wikipedia.org/wiki/Floating_point

You're getting back exactly what is in the file, which isn't always 
exactly what you expect...

> Is there any way i can fetch the decimal number as it is in Excel.

You probably want to use DataFormatter, which applies excel style 
formatting rules to raw numbers to give you strings like in Excel

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org