I cannot promise that this WILL work but it ought to even though it is a very
convoluted way to solve the problem and I can only apologise that I cannot
think of anything better. Try using the
org.apache.poi.hssf.usermodel.HSSFDataFormatter class to convert the number
into a String but a String that is formatted as the cell would be, then
convert the String back into a double value. Something like this;

   public double getNumericCellValue(HSSFSheet hssfsheet, int i, int j)
   {
       HSSFCell hssfcell = getCell(hssfsheet, i , j );
       String strValue = HSSFDataFormatter.formatCellValue(hssfCell);
       double value = Double.parseDouble(strValue);
       return value;
   }

Another possible solution would have been to recover the data formatting
String applied to the cell, counted how may digits followed the decimal
separator and then truncated the double value at the appropriate point.

The real villain it seems to me is that old problem; accurately representing
numerical values.

Hope this helps a little.

Yours

Mark B


Bugzilla from [email protected] wrote:
> 
> https://issues.apache.org/bugzilla/show_bug.cgi?id=48124
> 
>            Summary: The Precision is lossed when i prasing excel used poi
>            Product: POI
>            Version: 3.5-FINAL
>           Platform: PC
>         OS/Version: Linux
>             Status: NEW
>           Severity: critical
>           Priority: P5
>          Component: HSSF
>         AssignedTo: [email protected]
>         ReportedBy: [email protected]
> 
> 
> hi
>   I am so sorry ,my english is not very well.But i have some trouble in
> using
> POI to parse excel,the precision is lossed.
>   For exampe,the right amount is:1860.68,but the result is
> 1860.6800000000001
> when i using poi in Linux 64-bit and the poi version is poi-3.5-FINAL.
>   If I run the project in Linux 32-bit,the result is right.But I can't
> change
> the os because it's a production.
>   Pls give me some suggestions and i must solve it quickly because many
> users
> can't use  our product.
> 
>   This is the testing code in Linux RatHat5.0 64-bit :
> 
>    /**
>     *This function return 1860.6800000000001 which i see in the log,but
> the 
>     * amount is 1860.68 in the excel
>     **/
>    public double getNumericCellValue(HSSFSheet hssfsheet, int i, int j)
>    {
>        HSSFCell hssfcell = getCell(hssfsheet, i , j );
>        double value=hssfcell.getNumericCellValue();
>        return vaule;
> 
>    }
> 
> -- 
> Configure bugmail:
> https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are the assignee for the bug.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/DO-NOT-REPLY--Bug-48124--New%3A-The-Precision-is-lossed-when-i-prasing-excel-used-poi-tp26194123p26202022.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to