Forwarding to the right place.

Mark


-------- Forwarded Message --------
Subject:        Accuration Bug
Date:   Wed, 28 Sep 2016 10:00:47 +0000
From:   Sun, Ricky <he....@fmr.com>
Reply-To:       tradema...@apache.org
To:     webmas...@foo.com <webmas...@foo.com>, webmas...@toddsbeer.org
<webmas...@toddsbeer.org>, tradema...@apache.org <tradema...@apache.org>



Dear Sirs,


Thank you for your poi jars working on Excel. I’m using it to develop
project using java.

I got an bug about accurate calculation. The result from java is 0.07
base on the formula in Excel, but actually, the result is 0.06 in Excel.

I think the bug can be fixed by using BigDecimal type to calculate
formula in java.


Thanks,

Ricky

Attachment: test.xlsx
Description: MS-Excel 2007 spreadsheet

package com.fmr.svc.auto.score.dda;

import java.text.ParseException;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Test extends TestCalculation {

        public static void main(String[] args) {
                try {
                        get();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

        public static void get() throws Exception {

                String excelPathFile = "..\\yourexcel\\test.xlsx";
                XSSFWorkbook workbook = getWorkBook(excelPathFile);
                // refresh excel tool engine
                
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();

                double value = test(getCellByRowCol(workbook, "abc", 5, 0));

                System.out.println(value);
        }

        public static double test(XSSFCell cell)
                        throws ParseException {

                System.out.println(cell.getCellFormula());
                double cellValue = cell.getNumericCellValue();

                return cellValue;

        }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to