Search in sources :

Example 81 with RoundingMode

use of java.math.RoundingMode in project robovm by robovm.

the class BigDecimalArithmeticTest method testDivideBigDecimalScaleMathContextHALF_EVEN.

/**
     * divide(BigDecimal, MathContext)
     */
public void testDivideBigDecimalScaleMathContextHALF_EVEN() {
    String a = "3736186567876876578956958765675671119238118911893939591735";
    int aScale = 45;
    String b = "134432345432345748766876876723342238476237823787879183470";
    int bScale = 70;
    int precision = 21;
    RoundingMode rm = RoundingMode.HALF_EVEN;
    MathContext mc = new MathContext(precision, rm);
    String c = "2.77923185514690367475E+26";
    int resScale = -6;
    BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
    BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
    BigDecimal result = aNumber.divide(bNumber, mc);
    assertEquals("incorrect value", c, result.toString());
    assertEquals("incorrect scale", resScale, result.scale());
}
Also used : RoundingMode(java.math.RoundingMode) BigInteger(java.math.BigInteger) MathContext(java.math.MathContext) BigDecimal(java.math.BigDecimal)

Example 82 with RoundingMode

use of java.math.RoundingMode in project robovm by robovm.

the class BigDecimalArithmeticTest method testDivideBigDecimalScaleRoundingModeHALF_UP.

/**
     * divide(BigDecimal, scale, RoundingMode)
     */
public void testDivideBigDecimalScaleRoundingModeHALF_UP() {
    String a = "3736186567876876578956958765675671119238118911893939591735";
    int aScale = -51;
    String b = "74723342238476237823787879183470";
    int bScale = 45;
    int newScale = 3;
    RoundingMode rm = RoundingMode.HALF_UP;
    String c = "50000260373164286401361913262100972218038099522752460421" + "05959924024355721031761947728703598332749334086415670525" + "3761096961.670";
    BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
    BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
    BigDecimal result = aNumber.divide(bNumber, newScale, rm);
    assertEquals("incorrect value", c, result.toString());
    assertEquals("incorrect scale", newScale, result.scale());
}
Also used : RoundingMode(java.math.RoundingMode) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Example 83 with RoundingMode

use of java.math.RoundingMode in project robovm by robovm.

the class BigDecimalCompareTest method testAbsMathContextPos.

/**
     * Abs(MathContext) of a positive BigDecimal
     */
public void testAbsMathContextPos() {
    String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
    BigDecimal aNumber = new BigDecimal(a);
    int precision = 41;
    RoundingMode rm = RoundingMode.HALF_EVEN;
    MathContext mc = new MathContext(precision, rm);
    String result = "1.2380964839238475457356735674573563567890E+53";
    int resScale = -13;
    BigDecimal res = aNumber.abs(mc);
    assertEquals("incorrect value", result, res.toString());
    assertEquals("incorrect scale", resScale, res.scale());
}
Also used : RoundingMode(java.math.RoundingMode) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext)

Example 84 with RoundingMode

use of java.math.RoundingMode in project robovm by robovm.

the class BigDecimalCompareTest method testAbsMathContextNeg.

/**
     * Abs(MathContext) of a negative BigDecimal
     */
public void testAbsMathContextNeg() {
    String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
    BigDecimal aNumber = new BigDecimal(a);
    int precision = 15;
    RoundingMode rm = RoundingMode.HALF_DOWN;
    MathContext mc = new MathContext(precision, rm);
    String result = "1.23809648392385E+53";
    int resScale = -39;
    BigDecimal res = aNumber.abs(mc);
    assertEquals("incorrect value", result, res.toString());
    assertEquals("incorrect scale", resScale, res.scale());
}
Also used : RoundingMode(java.math.RoundingMode) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext)

Example 85 with RoundingMode

use of java.math.RoundingMode in project robovm by robovm.

the class BigDecimalConstructorsTest method testConstrCharIntIntMathContextException2.

/**
     * new BigDecimal(char[] value, int offset, int len, MathContext mc); 
     */
public void testConstrCharIntIntMathContextException2() {
    char[] value = { '-', '1', '2', '3', '8', '0', ',', '4', '7', '3', '8', 'E', '-', '4', '2', '3' };
    int offset = 3;
    int len = 120;
    int precision = 4;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    try {
        new BigDecimal(value, offset, len, mc);
        fail("NumberFormatException has not been thrown");
    } catch (NumberFormatException e) {
    }
}
Also used : RoundingMode(java.math.RoundingMode) MathContext(java.math.MathContext) BigDecimal(java.math.BigDecimal)

Aggregations

RoundingMode (java.math.RoundingMode)206 BigDecimal (java.math.BigDecimal)127 BigInteger (java.math.BigInteger)88 MathContext (java.math.MathContext)72 GwtIncompatible (com.google.common.annotations.GwtIncompatible)39 DecimalFormat (java.text.DecimalFormat)5 IDataMap (permafrost.tundra.data.IDataMap)5 Test (org.junit.Test)3 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ButtonGroup (javax.swing.ButtonGroup)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 JRadioButton (javax.swing.JRadioButton)2 JSpinner (javax.swing.JSpinner)2 SpinnerNumberModel (javax.swing.SpinnerNumberModel)2