Java 类java.math.BigDecimal 实例源码

项目:Rey-MusicPlayer    文件:RangeSeekBar.java   
public static <E extends Number> NumberType fromNumber(E value) throws IllegalArgumentException {
    if (value instanceof Long) {
        return LONG;
    }
    if (value instanceof Double) {
        return DOUBLE;
    }
    if (value instanceof Integer) {
        return INTEGER;
    }
    if (value instanceof Float) {
        return FLOAT;
    }
    if (value instanceof Short) {
        return SHORT;
    }
    if (value instanceof Byte) {
        return BYTE;
    }
    if (value instanceof BigDecimal) {
        return BIG_DECIMAL;
    }
    throw new IllegalArgumentException("Number class '" + value.getClass().getName() + "' is not supported");
}
项目:SoftUni    文件:p04_EuroTrip.java   
public static void main(String[] args){
    // Create new scanner
    Scanner input = new Scanner(System.in);
    // Read the quantity as a double value
    double wurst = input.nextDouble();
    double pricePerKilo = 1.20;
    BigDecimal priceInBGN = new BigDecimal((pricePerKilo * wurst));
    // Multiply the price in BGN with price in DM
    BigDecimal exchangeRate = new BigDecimal("4210500000000");
    BigDecimal neededDM = exchangeRate.multiply(priceInBGN);

    System.out.printf("%.2f marks", neededDM);
}
项目:oscm    文件:BillingServiceBeanIT.java   
@Test
public void testChangeUserAssignmentPeriodPricesForUsedPriceModelBeginOfJanuary()
        throws Exception {
    final int testMonth = Calendar.JANUARY;
    final int testDay = 1;
    BigDecimal etalonPrice = P_1_PRICE_PER_PERIOD
            .add(new BigDecimal(12345));

    final long billingTime = getBillingTime(testYear, testMonth, testDay);

    creSub(P_1_ID, getDate(testYear, testMonth, -2, 8, 0));
    subAddUser(SUBSCRIPTION_ID, "anton",
            getDate(testYear, testMonth, -2, 8, 0));

    // now change the price for the period on the last day of the month in
    // the billing period. Finally, the price must be reflected in the costs
    // - for the entire period.
    updSubscriptionPrices(P_1_PRICE_LOGIN, P_1_PRICE_UPLOAD,
            P_1_PRICE_LOGOUT, getDate(testYear, testMonth, 27, 23, 59),
            P_1_PRICE_PER_PERIOD, new BigDecimal(12345));

    updSubscriptionPrices(P_1_PRICE_LOGIN, P_1_PRICE_UPLOAD,
            P_1_PRICE_LOGOUT, getDate(testYear, testMonth, 35, 23, 59),
            P_1_PRICE_PER_PERIOD, P_1_PRICE_PER_USER);

    startBillingRun(billingTime);

    Date periods[][] = new Date[][] { { getStartDate(testYear, testMonth),
            getEndDate(testYear, testMonth) } };

    verify(periods, etalonPrice, testMonth);
    xmlValidator.validateBillingResultXML();
}
项目:ukubuka-core    文件:UkubukaTransformerTest.java   
@Test
public void test_performOperations_avg_success()
        throws PipelineException, TransformException {
    TransformOperations transformOperation = new TransformOperations();
    transformOperation.setType(TransformOperation.AVG);
    transformOperation.setSource("foobar");
    transformOperation.setTarget("data[1]");

    List<String> fileHeader = new ArrayList<>(Arrays.asList("foo", "bar"));
    List<FileRecord> fileRecords = new ArrayList<>(Arrays.asList(
            new FileRecord(new ArrayList<>(
                    Arrays.asList("bar", String.valueOf("3")))),
            new FileRecord(new ArrayList<>(
                    Arrays.asList("foo", String.valueOf("3"))))));
    List<TransformOperations> operationsList = new ArrayList<>(
            Arrays.asList(transformOperation));

    Mockito.when(
            expressionEvaluator.evaluate(Mockito.any(FileContents.class),
                    Mockito.any(FileRecord.class), Mockito.anyString()))
            .thenReturn(new BigDecimal(3));

    Transform transforms = new Transform();
    transforms.setId("foo-X");
    TransformOperationsType transformOperationsType = new TransformOperationsType();
    transformOperationsType.setColumn(operationsList);
    transforms.setOperations(transformOperationsType);
    Map<String, FileContents> dataFiles = new HashMap<>();
    dataFiles.put("foo-X", new FileContents(fileHeader, fileRecords));

    UkubukaSchema ukubukaSchema = new UkubukaSchema();
    ukubukaSchema.setTransforms(Arrays.asList(transforms));

    ukubukaTransformer.performOperations(dataFiles, ukubukaSchema);

    Mockito.verify(expressionEvaluator, Mockito.times(2)).evaluate(
            Mockito.any(FileContents.class), Mockito.any(FileRecord.class),
            Mockito.anyString());
    assertNotNull(dataFiles.get("foo-X").getAggregations().get("foobar"));
}
项目:openjdk-systemtest    文件:TestSuite027.java   
public void testItem_0183()
{
  rc_byte = (new BigDecimal("0")).byteValueExact();
  Assert.assertEquals(0, rc_byte);
}
项目:openjdk-systemtest    文件:TestSuite034.java   
public void testItem_0688()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = (new BigDecimal("-3.2E-2147483646")).pow(-2147483648);
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite054.java   
public void testItem_0227()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = (new BigDecimal("-321")).remainder(new BigDecimal("0.0"));
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite012.java   
public void testItem_0899()
{
  boolean caught;
  caught = false;
  try {
    rc_long = (new BigDecimal("-1.8")).longValueExact();
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.61073825503355%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite025.java   
public void testItem_0425()
{
  boolean caught;
  caught = false;
  try {
    rc_long = (new BigDecimal("1E-2147483647")).longValueExact();
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite036.java   
public void testItem_0261()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = (new BigDecimal("1")).pow(2147483647, new MathContext("precision=1 roundingMode=HALF_UP"));
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite015.java   
public void testItem_0205()
{
  boolean caught;
  caught = false;
  try {
    rc_int = (new BigDecimal("-147573952452237459488.0E+2147483647")).intValueExact();
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.61073825503355%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite052.java   
public void testItem_0512()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = new BigDecimal("", new MathContext("precision=2147483647 roundingMode=HALF_UP"));
  }
  catch (java.lang.NumberFormatException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite052.java   
public void testItem_0401()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = (new BigDecimal("-2")).pow(-1, new MathContext("precision=2147483647 roundingMode=FLOOR"));
  }
  catch (java.lang.IllegalArgumentException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite035.java   
public void testItem_0120()
{
  boolean caught;
  caught = false;
  try {
    rc_short = (new BigDecimal("2147483647")).shortValueExact();
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite012.java   
public void testItem_0709()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = (new BigDecimal("2E+9")).setScale(2147483647);
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.61073825503355%", true, caught);
}
项目:openjdk-systemtest    文件:TestSuite025.java   
public void testItem_0982()
{
  rc_BigDecimal = (new BigDecimal("3.2E+2")).plus(new MathContext("precision=2147483647 roundingMode=HALF_UP"));
  Assert.assertEquals("3.2E+2", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite017.java   
public void testItem_0682()
{
  rc_BigDecimal = (new BigDecimal("-1")).movePointLeft(1);
  Assert.assertEquals("-0.1", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite029.java   
public void testItem_0524()
{
  rc_BigDecimal = (new BigDecimal("0.0")).setScale(-2147483648, java.math.RoundingMode.HALF_DOWN);
  Assert.assertEquals("0E+2147483648", rc_BigDecimal.toString());
}
项目:GitHub    文件:TestASM_BigDecimal.java   
public BigDecimal getDecimal() {
    return decimal;
}
项目:openjdk-systemtest    文件:TestSuite002.java   
public void testItem_0034()
{
  rc_BigInteger = (new BigDecimal("0")).unscaledValue();
  Assert.assertEquals("0", rc_BigInteger.toString());
}
项目:openjdk-systemtest    文件:TestSuite007.java   
public void testItem_0455()
{
  rc_BigDecimal = new BigDecimal(-1.0);
  Assert.assertEquals("-1", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite009.java   
public void testItem_0710()
{
  rc_int = (new BigDecimal("1")).scale();
  Assert.assertEquals(0, rc_int);
}
项目:openjdk-systemtest    文件:TestSuite050.java   
public void testItem_0518()
{
  rc_BigDecimal = (new BigDecimal("0")).plus();
  Assert.assertEquals("0", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite059.java   
public void testItem_0604()
{
  rc_int = (new BigDecimal("-214748365.7")).scale();
  Assert.assertEquals(1, rc_int);
}
项目:openjdk-systemtest    文件:TestSuite000.java   
public void testItem_0193()
{
  rc_BigDecimal = new BigDecimal(1.7976931348623157E308, new MathContext("precision=1 roundingMode=HALF_UP"));
  Assert.assertEquals("2E+308", rc_BigDecimal.toString());
}
项目:Hydrograph    文件:NumericFunctions.java   
/**
 * Rounds the {@code inputValue} to specified number of digits to the right of the decimal point.
 * This function always rounds up the number irrespective of the "{@code numberOfDigits} + 1" digit.
 *
 * @param inputValue     the float value to be rounded up
 * @param numberOfDigits the number of digits to round up the {@code inputValue}
 * @return rounded up {@code inputValue} value
 */
public static Float roundUp(Float inputValue, int numberOfDigits) {
    if (inputValue == null)
        return null;
    BigDecimal bigDecimal = new BigDecimal(inputValue);
    bigDecimal = bigDecimal.setScale(numberOfDigits, BigDecimal.ROUND_UP);
    return bigDecimal.floatValue();
}
项目:openjdk-systemtest    文件:TestSuite018.java   
public void testItem_0740()
{
  rc_BigDecimal = (new BigDecimal("32")).abs();
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite041.java   
public void testItem_0755()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), new MathContext("precision=2147483647 roundingMode=HALF_EVEN"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite010.java   
public void testItem_0195()
{
  rc_BigInteger = (new BigDecimal("1")).toBigInteger();
  Assert.assertEquals("1", rc_BigInteger.toString());
}
项目:openjdk-systemtest    文件:TestSuite043.java   
public void testItem_0228()
{
  rc_BigDecimal = (new BigDecimal("3E+1")).pow(0, new MathContext("precision=1 roundingMode=HALF_UP"));
  Assert.assertEquals("1", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite040.java   
public void testItem_0880()
{
  rc_BigDecimal = (new BigDecimal("-1E-2147483647")).negate(new MathContext("precision=2147483647 roundingMode=UP"));
  Assert.assertEquals("1E-2147483647", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite041.java   
public void testItem_0683()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), new MathContext("precision=0 roundingMode=HALF_UP"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite008.java   
public void testItem_0959()
{
  rc_BigDecimal = (new BigDecimal("1")).multiply(new BigDecimal("1"));
  Assert.assertEquals("1", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite035.java   
public void testItem_0516()
{
  rc_String = (new BigDecimal("0")).toEngineeringString();
  Assert.assertEquals("0", rc_String);
}
项目:openjdk-systemtest    文件:TestSuite034.java   
public void testItem_0825()
{
  rc_BigDecimal = new BigDecimal(1, new MathContext("precision=1 roundingMode=FLOOR"));
  Assert.assertEquals("1", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite038.java   
public void testItem_0679()
{
  rc_BigDecimal = (new BigDecimal("0")).movePointLeft(-2147483648);
  Assert.assertEquals("0", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite019.java   
public void testItem_0277()
{
  rc_BigDecimal_array = (new BigDecimal("1")).divideAndRemainder(new BigDecimal("1"));
}
项目:openjdk-systemtest    文件:TestSuite029.java   
public void testItem_0594()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), new MathContext("precision=1 roundingMode=HALF_UP"));
  Assert.assertEquals("3E+1", rc_BigDecimal.toString());
}
项目:openjdk-systemtest    文件:TestSuite048.java   
public void testItem_0260()
{
  rc_String = (new BigDecimal("-3E+2")).toPlainString();
  Assert.assertEquals("-300", rc_String);
}