use of java.math.MathContext in project j2objc by google.
the class BigDecimalArithmeticTest method testRoundMathContextHALF_DOWN.
/**
* round(BigDecimal, MathContext)
*/
public void testRoundMathContextHALF_DOWN() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = -45;
int precision = 75;
RoundingMode rm = RoundingMode.HALF_DOWN;
MathContext mc = new MathContext(precision, rm);
String res = "3.736186567876876578956958765675671119238118911893939591735E+102";
int resScale = -45;
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal result = aNumber.round(mc);
assertEquals("incorrect quotient value", res, result.toString());
assertEquals("incorrect quotient scale", resScale, result.scale());
}
use of java.math.MathContext in project j2objc by google.
the class BigDecimalArithmeticTest method testDivideBigDecimalScaleMathContextHALF_UP.
/**
* divide(BigDecimal, MathContext)
*/
public void testDivideBigDecimalScaleMathContextHALF_UP() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
int bScale = 70;
int precision = 21;
RoundingMode rm = RoundingMode.HALF_UP;
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());
}
use of java.math.MathContext in project j2objc by google.
the class BigDecimalArithmeticTest method testDivideToIntegralValueMathContextDOWN.
/**
* divideToIntegralValue(BigDecimal, MathContext)
*/
public void testDivideToIntegralValueMathContextDOWN() {
String a = "3736186567876876578956958769675785435673453453653543654354365435675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
int bScale = 70;
int precision = 75;
RoundingMode rm = RoundingMode.DOWN;
MathContext mc = new MathContext(precision, rm);
String c = "2.7792318551469036747477068339450205874992634417590178670822889E+62";
int resScale = -1;
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
BigDecimal result = aNumber.divideToIntegralValue(bNumber, mc);
assertEquals("incorrect value", c, result.toString());
assertEquals("incorrect scale", resScale, result.scale());
}
use of java.math.MathContext in project j2objc by google.
the class BigDecimalArithmeticTest method testDivideToIntegralValueMathContextUP.
/**
* divideToIntegralValue(BigDecimal, MathContext)
*/
public void testDivideToIntegralValueMathContextUP() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
int bScale = 70;
int precision = 32;
RoundingMode rm = RoundingMode.UP;
MathContext mc = new MathContext(precision, rm);
String c = "277923185514690367474770683";
int resScale = 0;
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
BigDecimal result = aNumber.divideToIntegralValue(bNumber, mc);
assertEquals("incorrect value", c, result.toString());
assertEquals("incorrect scale", resScale, result.scale());
}
use of java.math.MathContext 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());
}
Aggregations