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

(-)src/java/org/apache/poi/ss/formula/functions/MathX.java (-3 / +4 lines)
Lines 19-24 Link Here
19
19
20
import org.apache.poi.ss.util.NumberToTextConverter;
20
import org.apache.poi.ss.util.NumberToTextConverter;
21
21
22
import java.math.BigDecimal;
23
22
/**
24
/**
23
 * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
25
 * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
24
 * This class is an extension to the standard math library
26
 * This class is an extension to the standard math library
Lines 108-117 Link Here
108
110
109
        if (Double.isNaN(n) || Double.isInfinite(n)) {
111
        if (Double.isNaN(n) || Double.isInfinite(n)) {
110
            retval = Double.NaN;
112
            retval = Double.NaN;
113
        } else {
114
            retval = new BigDecimal(NumberToTextConverter.toText(n)).setScale(p, java.math.RoundingMode.DOWN).doubleValue();
111
        }
115
        }
112
        else {
113
            retval = java.math.BigDecimal.valueOf(n).setScale(p, java.math.RoundingMode.DOWN).doubleValue();
114
        }
115
116
116
        return retval;
117
        return retval;
117
    }
118
    }
(-)src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java (-8 / +14 lines)
Lines 709-715 Link Here
709
    public void testRoundDown() {
709
    public void testRoundDown() {
710
        double d = 0;
710
        double d = 0;
711
        int p = 0;
711
        int p = 0;
712
        
712
713
        d = 396d * 2.32d; p = 9;
714
        assertEquals("roundDown ", 918.72d, MathX.roundDown(d, p));
715
716
        d = 396d * 2.32d; p = 2;
717
        assertEquals("roundDown ", 918.72d, MathX.roundDown(d, p));
718
713
        d = 0; p = 0;
719
        d = 0; p = 0;
714
        assertEquals("roundDown ", 0, MathX.roundDown(d, p));
720
        assertEquals("roundDown ", 0, MathX.roundDown(d, p));
715
        
721
        
Lines 753-777 Link Here
753
        assertEquals("roundDown ", 100, MathX.roundDown(d, p));
759
        assertEquals("roundDown ", 100, MathX.roundDown(d, p));
754
        
760
        
755
        d = 0.049999999999999975d; p = 2;
761
        d = 0.049999999999999975d; p = 2;
756
        assertEquals("round ", 0.04d, MathX.roundDown(d, p));
762
        assertEquals("roundDown ", 0.05d, MathX.roundDown(d, p));
757
763
758
        d = 0.049999999999999975d; p = 1;
764
        d = 0.049999999999999975d; p = 1;
759
        assertEquals("round ", 0.0d, MathX.roundDown(d, p));
765
        assertEquals("roundDown ", 0.0d, MathX.roundDown(d, p));
760
        
766
        
761
        d = Double.NaN; p = 1;
767
        d = Double.NaN; p = 1;
762
        assertEquals("round ", Double.NaN, MathX.roundDown(d, p));
768
        assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
763
769
764
        d = Double.POSITIVE_INFINITY; p = 1;
770
        d = Double.POSITIVE_INFINITY; p = 1;
765
        assertEquals("round ", Double.NaN, MathX.roundDown(d, p));
771
        assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
766
772
767
        d = Double.NEGATIVE_INFINITY; p = 1;
773
        d = Double.NEGATIVE_INFINITY; p = 1;
768
        assertEquals("round ", Double.NaN, MathX.roundDown(d, p));
774
        assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
769
775
770
        d = Double.MAX_VALUE; p = 1;
776
        d = Double.MAX_VALUE; p = 1;
771
        assertEquals("round ", Double.MAX_VALUE, MathX.roundDown(d, p));
777
        assertEquals("roundDown ", Double.MAX_VALUE, MathX.roundDown(d, p));
772
778
773
        d = Double.MIN_VALUE; p = 1;
779
        d = Double.MIN_VALUE; p = 1;
774
        assertEquals("round ", 0.0d, MathX.roundDown(d, p));
780
        assertEquals("roundDown ", 0.0d, MathX.roundDown(d, p));
775
    }
781
    }
776
782
777
    public void testRoundUp() {
783
    public void testRoundUp() {

Return to bug 56741