How can I set a percentage formula in Apache POI? -


How can I set the formula with the calculation of percentage value in Apache POI?

And how can it be a full value?

For example, if it is -4.00% , then it should be 4.00

By the form, you have 2 cells with A1 and B1 numbers (in my example, these numbers are 2411 and 1333), and the formula in the cell is called

  C = A1 / B1   

try this

  System.out.println ("formula" + cell 1 .getCellFormula ()); If (cell 1.getCellType () == cell.cell_TYPE_FORMULA) {cellvalue CV = evaluator. Evaluation (cell 1); System.out.println ("cv" + cv.formatAsString ()); Decimalable df = new passphrase ("###. ##%"); System.out.println ("formatted as percent" + df.format (Math.base (Cell 1.getNumericCellValue ())); }   

is output

  formula A1 / B1 cv 1.808702175543886% formatted as 180.87%   

A1 Change negative, and it will still work.

Comments