View | Details | Raw Unified | Return to bug 66047
Collapse All | Expand All

(-)a/poi/src/main/java/org/apache/poi/ss/formula/atp/MRound.java (-1 / +6 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.ss.formula.atp;
18
package org.apache.poi.ss.formula.atp;
19
19
20
import java.math.BigDecimal;
21
import java.math.RoundingMode;
22
20
import org.apache.poi.ss.formula.OperationEvaluationContext;
23
import org.apache.poi.ss.formula.OperationEvaluationContext;
21
import org.apache.poi.ss.formula.eval.*;
24
import org.apache.poi.ss.formula.eval.*;
22
import org.apache.poi.ss.formula.functions.FreeRefFunction;
25
import org.apache.poi.ss.formula.functions.FreeRefFunction;
Lines 56-62 Link Here
56
                    // Returns #NUM! because the number and the multiple have different signs
59
                    // Returns #NUM! because the number and the multiple have different signs
57
                    throw new EvaluationException(ErrorEval.NUM_ERROR);
60
                    throw new EvaluationException(ErrorEval.NUM_ERROR);
58
                }
61
                }
59
                result = multiple * Math.round( number / multiple );
62
                BigDecimal bdMultiple = BigDecimal.valueOf(multiple);
63
                result = bdMultiple.multiply(BigDecimal.valueOf(number).divide(bdMultiple, 0, RoundingMode.HALF_UP))
64
                        .doubleValue();
60
            }
65
            }
61
            NumericFunction.checkValue(result);
66
            NumericFunction.checkValue(result);
62
            return new NumberEval(result);
67
            return new NumberEval(result);
(-)a/poi/src/test/java/org/apache/poi/ss/formula/atp/TestMRound.java (+5 lines)
Lines 51-56 Link Here
51
        cell4.setCellFormula("MROUND(5, -2)");
51
        cell4.setCellFormula("MROUND(5, -2)");
52
        Cell cell5 = sh.createRow(0).createCell(0);
52
        Cell cell5 = sh.createRow(0).createCell(0);
53
        cell5.setCellFormula("MROUND(5, 0)");
53
        cell5.setCellFormula("MROUND(5, 0)");
54
        Cell cell6 = sh.createRow(0).createCell(0);
55
        cell6.setCellFormula("MROUND(0.79*7.5, 0.05)");
54
56
55
        double accuracy = 1E-9;
57
        double accuracy = 1E-9;
56
58
Lines 70-74 Link Here
70
72
71
        assertEquals(0.0, evaluator.evaluate(cell5).getNumberValue(), 0,
73
        assertEquals(0.0, evaluator.evaluate(cell5).getNumberValue(), 0,
72
                     "Returns 0 because the multiple is 0");
74
                     "Returns 0 because the multiple is 0");
75
76
         assertEquals(5.95, evaluator.evaluate(cell6).getNumberValue(), 0,
77
                     "Rounds 5.925 to a nearest multiple of 0.05 (5.95)");
73
    }
78
    }
74
}
79
}

Return to bug 66047