本文整理汇总了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");
}
示例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);
}
示例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();
}
示例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"));
}
示例5: testItem_0183
import java.math.BigDecimal; //导入依赖的package包/类
public void testItem_0183()
{
rc_byte = (new BigDecimal("0")).byteValueExact();
Assert.assertEquals(0, rc_byte);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}