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());
}
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());
}
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) {
}
}
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);
}
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);
}
Aggregations