當前位置: 首頁>>代碼示例>>Java>>正文


Java BigDecimal類代碼示例

本文整理匯總了Java中java.math.BigDecimal的典型用法代碼示例。如果您正苦於以下問題:Java BigDecimal類的具體用法?Java BigDecimal怎麽用?Java BigDecimal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BigDecimal類屬於java.math包,在下文中一共展示了BigDecimal類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fromNumber

import java.math.BigDecimal; //導入依賴的package包/類
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");
}
 
開發者ID:reyanshmishra,項目名稱:Rey-MusicPlayer,代碼行數:25,代碼來源:RangeSeekBar.java

示例2: main

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:kostovhg,項目名稱:SoftUni,代碼行數:14,代碼來源:p04_EuroTrip.java

示例3: testChangeUserAssignmentPeriodPricesForUsedPriceModelBeginOfJanuary

import java.math.BigDecimal; //導入依賴的package包/類
@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();
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:34,代碼來源:BillingServiceBeanIT.java

示例4: test_performOperations_avg_success

import java.math.BigDecimal; //導入依賴的package包/類
@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"));
}
 
開發者ID:ukubuka,項目名稱:ukubuka-core,代碼行數:41,代碼來源:UkubukaTransformerTest.java

示例5: testItem_0183

import java.math.BigDecimal; //導入依賴的package包/類
public void testItem_0183()
{
  rc_byte = (new BigDecimal("0")).byteValueExact();
  Assert.assertEquals(0, rc_byte);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:6,代碼來源:TestSuite027.java

示例6: testItem_0688

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite034.java

示例7: testItem_0869

import java.math.BigDecimal; //導入依賴的package包/類
public void testItem_0869()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = new BigDecimal("J>[email protected];9CNPW>X>EIS>Q;J>6VX1VN:BK>[email protected]<7JAUNJB9AK7404:CTHY9CRAM:X1S3KYESVSHQXH1L>2YH", new MathContext("precision=2147483647 roundingMode=HALF_UP"));
  }
  catch (java.lang.NumberFormatException e) {
    caught = true;
  }
  Assert.assertEquals("89.93288590604027%", true, caught);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite003.java

示例8: testItem_0227

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite054.java

示例9: testItem_0899

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite012.java

示例10: testItem_0425

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite025.java

示例11: testItem_0261

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite036.java

示例12: testItem_0205

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite015.java

示例13: testItem_0512

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite052.java

示例14: testItem_0401

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite052.java

示例15: testItem_0120

import java.math.BigDecimal; //導入依賴的package包/類
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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite035.java


注:本文中的java.math.BigDecimal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。