Search in sources :

Example 86 with BigDecimal

use of java.math.BigDecimal in project guava by google.

the class LongMathTest method testDivNonZero.

// TODO
@GwtIncompatible
// TODO(cpovirk): File BigDecimal.divide() rounding bug.
@AndroidIncompatible
public void testDivNonZero() {
    for (long p : NONZERO_LONG_CANDIDATES) {
        for (long q : NONZERO_LONG_CANDIDATES) {
            for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) {
                long expected = new BigDecimal(valueOf(p)).divide(new BigDecimal(valueOf(q)), 0, mode).longValue();
                long actual = LongMath.divide(p, q, mode);
                if (expected != actual) {
                    failFormat("expected divide(%s, %s, %s) = %s; got %s", p, q, mode, expected, actual);
                }
            }
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) BigDecimal(java.math.BigDecimal) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 87 with BigDecimal

use of java.math.BigDecimal in project guava by google.

the class DoubleMathTest method testRoundIntegralDoubleToBigInteger.

// DoubleMath.roundToBigInteger(double, RoundingMode)
@GwtIncompatible
public void testRoundIntegralDoubleToBigInteger() {
    for (double d : INTEGRAL_DOUBLE_CANDIDATES) {
        for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) {
            BigDecimal expected = new BigDecimal(d).setScale(0, mode);
            assertEquals(expected.toBigInteger(), DoubleMath.roundToBigInteger(d, mode));
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) BigDecimal(java.math.BigDecimal) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 88 with BigDecimal

use of java.math.BigDecimal in project j2objc by google.

the class BigDecimalTest method test_abs.

/**
	 * @tests java.math.BigDecimal#abs()
	 */
public void test_abs() {
    BigDecimal big = new BigDecimal("-1234");
    BigDecimal bigabs = big.abs();
    assertTrue("the absolute value of -1234 is not 1234", bigabs.toString().equals("1234"));
    big = new BigDecimal(new BigInteger("2345"), 2);
    bigabs = big.abs();
    assertTrue("the absolute value of 23.45 is not 23.45", bigabs.toString().equals("23.45"));
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Example 89 with BigDecimal

use of java.math.BigDecimal in project j2objc by google.

the class BigDecimalTest method test_subtractLjava_math_BigDecimal.

/**
	 * @tests java.math.BigDecimal#subtract(java.math.BigDecimal)
	 */
public void test_subtractLjava_math_BigDecimal() {
    BigDecimal sub1 = new BigDecimal("13948");
    BigDecimal sub2 = new BigDecimal("2839.489");
    BigDecimal result = sub1.subtract(sub2);
    assertTrue("13948 - 2839.489 is wrong: " + result, result.toString().equals("11108.511") && result.scale() == 3);
    BigDecimal result2 = sub2.subtract(sub1);
    assertTrue("2839.489 - 13948 is wrong", result2.toString().equals("-11108.511") && result2.scale() == 3);
    assertTrue("13948 - 2839.489 is not the negative of 2839.489 - 13948", result.equals(result2.negate()));
    sub1 = new BigDecimal(value, 1);
    sub2 = new BigDecimal("0");
    result = sub1.subtract(sub2);
    assertTrue("1234590.8 - 0 is wrong", result.equals(sub1));
    sub1 = new BigDecimal(1.234E-03);
    sub2 = new BigDecimal(3.423E-10);
    result = sub1.subtract(sub2);
    assertTrue("1.234E-03 - 3.423E-10 is wrong, " + result.doubleValue(), result.doubleValue() == 0.0012339996577);
    sub1 = new BigDecimal(1234.0123);
    sub2 = new BigDecimal(1234.0123000);
    result = sub1.subtract(sub2);
    assertTrue("1234.0123 - 1234.0123000 is wrong, " + result.doubleValue(), result.doubleValue() == 0.0);
}
Also used : BigDecimal(java.math.BigDecimal)

Example 90 with BigDecimal

use of java.math.BigDecimal in project j2objc by google.

the class BigDecimalTest method test_negate.

/**
	 * @tests java.math.BigDecimal#negate()
	 */
public void test_negate() {
    BigDecimal negate1 = new BigDecimal(value2, 7);
    assertTrue("the negate of 1233.4560000 is not -1233.4560000", negate1.negate().toString().equals("-1233.4560000"));
    negate1 = new BigDecimal("-23465839");
    assertTrue("the negate of -23465839 is not 23465839", negate1.negate().toString().equals("23465839"));
    negate1 = new BigDecimal(-3.456E6);
    assertTrue("the negate of -3.456E6 is not 3.456E6", negate1.negate().negate().equals(negate1));
}
Also used : BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)5274 Test (org.junit.Test)834 BigInteger (java.math.BigInteger)657 Test (org.testng.annotations.Test)626 LocalDate (org.joda.time.LocalDate)409 ArrayList (java.util.ArrayList)393 ResultSet (java.sql.ResultSet)251 MathContext (java.math.MathContext)220 Timestamp (java.sql.Timestamp)211 PreparedStatement (java.sql.PreparedStatement)207 Date (java.util.Date)175 SQLException (java.sql.SQLException)170 HashMap (java.util.HashMap)157 UUID (java.util.UUID)149 Invoice (org.killbill.billing.invoice.api.Invoice)148 List (java.util.List)136 DateTime (org.joda.time.DateTime)132 RoundingMode (java.math.RoundingMode)129 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)104 Session (org.hibernate.Session)96