Search in sources :

Example 61 with RoundingMode

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

the class BigDecimalConstructorsTest method testConstrLongMathContext.

/**
     * new BigDecimal(long, MathContext)
     */
public void testConstrLongMathContext() {
    long a = 4576578677732546982L;
    int precision = 5;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    String res = "45766";
    int resScale = -14;
    BigDecimal result = new BigDecimal(a, mc);
    assertEquals("incorrect value", res, result.unscaledValue().toString());
    assertEquals("incorrect scale", resScale, result.scale());
}
Also used : RoundingMode(java.math.RoundingMode) MathContext(java.math.MathContext) BigDecimal(java.math.BigDecimal)

Example 62 with RoundingMode

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

the class BigDecimalConstructorsTest method testConstrIntMathContext.

/**
     * new BigDecimal(int, MathContext)
     */
public void testConstrIntMathContext() {
    int a = 732546982;
    int precision = 21;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    String res = "732546982";
    int resScale = 0;
    BigDecimal result = new BigDecimal(a, mc);
    assertEquals("incorrect value", res, result.unscaledValue().toString());
    assertEquals("incorrect scale", resScale, result.scale());
}
Also used : RoundingMode(java.math.RoundingMode) MathContext(java.math.MathContext) BigDecimal(java.math.BigDecimal)

Example 63 with RoundingMode

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

the class BigDecimalConstructorsTest method testConstrCharIntIntMathContext.

/**
     * new BigDecimal(char[] value, int offset, int len, MathContext mc); 
     */
public void testConstrCharIntIntMathContext() {
    char[] value = { '-', '1', '2', '3', '8', '0', '.', '4', '7', '3', '8', 'E', '-', '4', '2', '3' };
    int offset = 3;
    int len = 12;
    int precision = 4;
    RoundingMode rm = RoundingMode.CEILING;
    MathContext mc = new MathContext(precision, rm);
    BigDecimal result = new BigDecimal(value, offset, len, mc);
    String res = "3.805E-40";
    int resScale = 43;
    assertEquals("incorrect value", res, result.toString());
    assertEquals("incorrect scale", resScale, result.scale());
    try {
        // Regression for HARMONY-783
        new BigDecimal(new char[] {}, 0, 0, MathContext.DECIMAL32);
        fail("NumberFormatException has not been thrown");
    } catch (NumberFormatException e) {
    }
}
Also used : RoundingMode(java.math.RoundingMode) MathContext(java.math.MathContext) BigDecimal(java.math.BigDecimal)

Example 64 with RoundingMode

use of java.math.RoundingMode in project head by mifos.

the class MoneyUtils method initialRound.

/**
     * Does the rounding based on <br />
     * {@link Money#round(Money, BigDecimal, RoundingMode)} with <br />
     * {@link AccountingRules#getInitialRoundOffMultiple()} (Default 1) <br />
     * {@link AccountingRules#getInitialRoundingMode()} (Default
     * {@link RoundingMode#HALF_UP}
     *
     * @param money
     * @return {@link Money}
     */
public static Money initialRound(Money money) {
    BigDecimal initialRoundOffMutiple = AccountingRules.getInitialRoundOffMultiple(money.getCurrency());
    RoundingMode initialRoundingMode = AccountingRules.getInitialRoundingMode();
    return Money.round(money, initialRoundOffMutiple, initialRoundingMode);
}
Also used : RoundingMode(java.math.RoundingMode) BigDecimal(java.math.BigDecimal)

Example 65 with RoundingMode

use of java.math.RoundingMode in project head by mifos.

the class MoneyUtils method finalRound.

/**
     * Does the rounding based on <br />
     * {@link Money#round(Money, BigDecimal, RoundingMode)} with <br />
     * {@link AccountingRules#getFinalRoundOffMultiple()} (Default 1) <br />
     * {@link AccountingRules#getFinalRoundingMode()} (Default
     * {@link RoundingMode#CEILING}
     *
     * @param money
     * @return {@link Money}
     */
public static Money finalRound(Money money) {
    BigDecimal finalRoundOffMutiple = AccountingRules.getFinalRoundOffMultiple(money.getCurrency());
    RoundingMode finalRoundingMode = AccountingRules.getFinalRoundingMode();
    return Money.round(money, finalRoundOffMutiple, finalRoundingMode);
}
Also used : RoundingMode(java.math.RoundingMode) 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