use of java.math.MathContext in project robovm by robovm.
the class OldBigDecimalArithmeticTest method testDivideToIntegralValueMathContextNonTrivial.
public void testDivideToIntegralValueMathContextNonTrivial() {
MathContext mc;
BigDecimal a, b, res;
a = new BigDecimal("92345678901234567.8");
b = new BigDecimal("43");
res = a.multiply(b);
assertEquals("incorrect value", "3970864192753086415.4", res.toString());
mc = new MathContext(20, RoundingMode.DOWN);
a = new BigDecimal("3970864192753086415.4");
b = new BigDecimal("92345678901234567.8");
b = new BigDecimal("92345678901234567.8001");
assertEquals("incorrect value", "43", a.round(mc).divideToIntegralValue(b.round(mc)).toString());
res = a.divideToIntegralValue(b, mc);
assertEquals("incorrect value", "42", res.toString());
// mc = new MathContext(1, RoundingMode.DOWN);
// res = a.divideToIntegralValue(b, mc);
// assertEquals("incorrect value", "42", res.toString());
mc = new MathContext(17, RoundingMode.FLOOR);
a = new BigDecimal("518518513851851830");
b = new BigDecimal("12345678901234567.9");
assertEquals("incorrect value", "42", a.round(mc).divideToIntegralValue(b.round(mc)).toString());
res = a.divideToIntegralValue(b, mc);
assertEquals("incorrect value", "41", res.toString());
}
use of java.math.MathContext in project robovm by robovm.
the class OldBigDecimalConstructorsTest method testConstrDoubleMathContext_AndroidFailure.
public void testConstrDoubleMathContext_AndroidFailure() {
BigDecimal bd;
MathContext mc;
mc = new MathContext(11, RoundingMode.HALF_EVEN);
//
// VERY FUNNY:
// This works:
bd = new BigDecimal("123456789.125", mc);
assertEquals("incorrect value", "123456789.12", bd.toString());
// But this doesn't:
bd = new BigDecimal(123456789.125, mc);
assertEquals("incorrect value", "123456789.12", bd.toString());
bd = new BigDecimal(-123456789.125, mc);
assertEquals("incorrect value", "-123456789.12", bd.toString());
// AND HERE, TOO:
mc = new MathContext(11, RoundingMode.HALF_UP);
bd = new BigDecimal(123456789.125, mc);
assertEquals("incorrect value", "123456789.13", bd.toString());
bd = new BigDecimal(-123456789.125, mc);
assertEquals("incorrect value", "-123456789.13", bd.toString());
mc = new MathContext(11, RoundingMode.HALF_DOWN);
//
// SAME HERE:
// This works:
bd = new BigDecimal("123456789.125", mc);
assertEquals("incorrect value", "123456789.12", bd.toString());
// But this doesn't:
bd = new BigDecimal(123456789.125, mc);
assertEquals("incorrect value", "123456789.12", bd.toString());
bd = new BigDecimal(123456789.125, mc);
assertEquals("incorrect value", "123456789.12", bd.toString());
bd = new BigDecimal(-123456789.125, mc);
assertEquals("incorrect value", "-123456789.12", bd.toString());
}
use of java.math.MathContext in project robovm by robovm.
the class OldBigDecimalConvertTest method test_ByteValueStringZero.
public void test_ByteValueStringZero() {
String sNumber = "00000";
int iNumber = 0;
int iPresition = 0;
MathContext mc = new MathContext(iPresition, RoundingMode.HALF_UP);
BigDecimal bdNumber = new BigDecimal(sNumber, mc);
byte bNumber = bdNumber.byteValue();
assertTrue("incorrect byteValue", iNumber == bNumber);
}
use of java.math.MathContext in project robovm by robovm.
the class OldBigDecimalConvertTest method test_ByteValueCharZero.
public void test_ByteValueCharZero() {
char[] cNumber = { '-', '0', '.', '0' };
int iNumber = 0;
int iPresition = 0;
MathContext mc = new MathContext(iPresition, RoundingMode.HALF_UP);
BigDecimal bdNumber = new BigDecimal(cNumber, mc);
byte bNumber = bdNumber.byteValue();
assertTrue("incorrect byteValue", iNumber == bNumber);
}
use of java.math.MathContext in project robovm by robovm.
the class OldBigDecimalConvertTest method test_ByteValueExactCharZero.
public void test_ByteValueExactCharZero() {
char[] cNumber = { '-', '0', '.', '0' };
int iNumber = 0;
int iPresition = 5;
MathContext mc = new MathContext(iPresition, RoundingMode.HALF_DOWN);
BigDecimal bdNumber = new BigDecimal(cNumber, mc);
byte bNumber = bdNumber.byteValueExact();
assertTrue("incorrect byteValueExact", iNumber == bNumber);
}
Aggregations