本文整理汇总了Java中java.math.BigDecimal.multiply方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.multiply方法的具体用法?Java BigDecimal.multiply怎么用?Java BigDecimal.multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.multiply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bigDecimalToString_assci
import java.math.BigDecimal; //导入方法依赖的package包/类
public String bigDecimalToString_assci(BigDecimal bd) {
BigDecimal cur = bd.stripTrailingZeros();
StringBuilder sb = new StringBuilder();
for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) {
cur = cur.multiply(ASSCI_ONE_PLACE);
int ch = cur.intValue();
if (0 == ch) {
break;
}
cur = cur.subtract(new BigDecimal(ch));
//替换特殊字符
if (ch < 33) {
ch = 33;
} else if (ch == 127) {
ch = 126;
}
sb.append((char) ch);
}
return sb.toString();
}
示例2: format
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Formats a BigDecimal to produce a string.
* @param number The BigDecimal to format
* @param result where the text is to be appended
* @param delegate notified of locations of sub fields
* @exception ArithmeticException if rounding is needed with rounding
* mode being set to RoundingMode.UNNECESSARY
* @return The formatted number string
*/
private StringBuffer format(BigDecimal number, StringBuffer result,
FieldDelegate delegate) {
if (multiplier != 1) {
number = number.multiply(getBigDecimalMultiplier());
}
boolean isNegative = number.signum() == -1;
if (isNegative) {
number = number.negate();
}
synchronized(digitList) {
int maxIntDigits = getMaximumIntegerDigits();
int minIntDigits = getMinimumIntegerDigits();
int maxFraDigits = getMaximumFractionDigits();
int minFraDigits = getMinimumFractionDigits();
int maximumDigits = maxIntDigits + maxFraDigits;
digitList.set(isNegative, number, useExponentialNotation ?
((maximumDigits < 0) ? Integer.MAX_VALUE : maximumDigits) :
maxFraDigits, !useExponentialNotation);
return subformat(result, delegate, isNegative, false,
maxIntDigits, minIntDigits, maxFraDigits, minFraDigits);
}
}
示例3: doMath
import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal doMath(BigDecimal valueOne, Math operator, BigDecimal valueTwo)
{
switch (operator)
{
case SUM:
return valueOne.add(valueTwo);
case SUBTRACT:
return valueOne.subtract(valueTwo);
case MULTIPLY:
return valueOne.multiply(valueTwo);
case DIVIDE:
return valueOne.divide(valueTwo, 256, RoundingMode.CEILING);
default:
return new BigDecimal(0);
}
}
示例4: getSensitivityCorrelation
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal getSensitivityCorrelation(Sensitivity si, Sensitivity sk) {
int indexOf = InterestRateTenor.indexOf(si.getLabel1());
int indexOf2 = InterestRateTenor.indexOf(sk.getLabel1());
// NOTE: when we see a XCcy to Inflation correlation, we should use the XCcy correlation parameter, as such we put the XCcy option first
// so that it has precedence over Inflation (might need more complex logic in the future)
if (si.getRiskType().equals(RiskType.RISK_TYPE_XCCY_BASIS) || sk.getRiskType().equals(RiskType.RISK_TYPE_XCCY_BASIS)) {
return XCCY;
} else if (si.getRiskType().equals(RiskType.RISK_TYPE_INFLATION) || sk.getRiskType().equals(RiskType.RISK_TYPE_INFLATION) ||
si.getRiskType().equals(RiskType.RISK_TYPE_INFLATION_VOL) || sk.getRiskType().equals(RiskType.RISK_TYPE_INFLATION_VOL)) {
return INFLATION;
} else {
BigDecimal correlation = CORRELATIONS[indexOf][indexOf2];
if (!StringUtils.equalsIgnoreCase(si.getLabel2(), sk.getLabel2())) {
return correlation.multiply(SUB_CURVE_SAME_CCY);
} else {
return correlation;
}
}
}
示例5: stringToBigDecimal
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Return a BigDecimal representation of string 'str' suitable for use in a
* numerically-sorting order.
*/
public BigDecimal stringToBigDecimal(String str) {
// Start with 1/65536 to compute the first digit.
BigDecimal curPlace = ONE_PLACE;
BigDecimal result = BigDecimal.ZERO;
int len = Math.min(str.length(), MAX_CHARS);
for (int i = 0; i < len; i++) {
int codePoint = str.codePointAt(i);
result = result.add(tryDivide(new BigDecimal(codePoint), curPlace));
// advance to the next less significant place. e.g., 1/(65536^2) for the
// second char.
curPlace = curPlace.multiply(ONE_PLACE);
}
return result;
}
示例6: mul
import java.math.BigDecimal; //导入方法依赖的package包/类
public static double mul(double... ds) {
if(ds==null)
return 0;
BigDecimal count = new BigDecimal(String.valueOf(ds[0]));
if(ds!=null&&ds.length>0){
int i = 0;
for(double d:ds){
i++;
if(i==1)
continue;
BigDecimal val = new BigDecimal(Double.toString(d));
count = count.multiply(val);
}
}
return count.doubleValue();
}
示例7: testBigDecimals
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testBigDecimals() throws IOException
{
BigDecimal bigBase = new BigDecimal("1234567890344656736.125");
final BigDecimal[] input = new BigDecimal[] {
// 04-Jun-2017, tatu: these look like integral numbers in JSON so can't use:
// BigDecimal.ZERO,
// BigDecimal.ONE,
// BigDecimal.TEN,
BigDecimal.valueOf(-999.25),
bigBase,
bigBase.divide(new BigDecimal("5")),
bigBase.add(bigBase),
bigBase.multiply(new BigDecimal("1.23")),
bigBase.negate()
};
ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
JsonFactory f = JSON_F;
JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), bytes);
g.writeStartArray();
for (int i = 0; i < input.length; ++i) {
g.writeNumber(input[i]);
}
g.writeEndArray();
g.close();
byte[] data = bytes.toByteArray();
_testBigDecimals(f, input, data, 0, 100);
_testBigDecimals(f, input, data, 0, 3);
_testBigDecimals(f, input, data, 0, 1);
_testBigDecimals(f, input, data, 1, 100);
_testBigDecimals(f, input, data, 2, 3);
_testBigDecimals(f, input, data, 3, 1);
}
示例8: getFeeAmount
import java.math.BigDecimal; //导入方法依赖的package包/类
private BigDecimal getFeeAmount(BigDecimal amount, BigDecimal feeRatio, BigDecimal feeMax) {
BigDecimal fee = new BigDecimal(0);
if(null == amount || null == feeRatio) return fee;
//金额乘以费率 = 手续费
fee = amount.multiply(feeRatio);
//最大值为feeMax
if(null != feeMax && feeMax.compareTo(new BigDecimal("0")) >= 0) fee = fee.max(feeMax);
//设置精确到分并四舍五入
fee = fee.setScale(4, BigDecimal.ROUND_HALF_UP);
return fee;
}
示例9: decimalOp
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal decimalOp() {
BigDecimal v0 = args.get(0).valDecimal();
BigDecimal v1 = args.get(1).valDecimal();
if (this.nullValue = (args.get(0).isNull() || args.get(1).isNull()))
return new BigDecimal(0);
return v0.multiply(v1);
}
示例10: mul
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* @param first 第一个参数
* @param second 第二个参数
* @return 乘法
*/
public static Object mul(Object first,Object second) {
BigDecimal a=Utils.toBigDecimal(first);
BigDecimal b=Utils.toBigDecimal(second);
BigDecimal c=a.multiply(b);
return c.doubleValue();
}
示例11: calculateCurvatureMarginResidual
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* As defined in Appendix 1 of ISDA_SIMM_2.0_(PUBLIC).pdf
*/
static BigDecimal calculateCurvatureMarginResidual(List<BucketWeightedAggregation> aggregateByBucket) {
List<BucketWeightedAggregation> residuals = BucketWeightedAggregationUtils.filterOutNonResiduals(aggregateByBucket);
BigDecimal sum = ZERO;
for (BucketWeightedAggregation bucketWeightedAggregation : residuals) {
BigDecimal weightedSensitivitiesSum = WeightedSensitivityUtils.sumWeightSensitivities(bucketWeightedAggregation.getWeightedSensitivities());
BigDecimal calculateLambda = CurvatureMarginLambdaUtils.calculateLambda(bucketWeightedAggregation.getWeightedSensitivities());
BigDecimal product = calculateLambda.multiply(bucketWeightedAggregation.getAggregate());
BigDecimal riskFactorTotal = weightedSensitivitiesSum.add(product);
sum = sum.add(riskFactorTotal);
}
return sum.max(ZERO);
}
示例12: calculate
import java.math.BigDecimal; //导入方法依赖的package包/类
private static BigDecimal calculate(String input) {
int i = 1;
while (i < input.length() && !order.containsKey(input.charAt(i)))
i++;
String var = input.substring(0, i);
BigDecimal value = variables.getOrDefault(var, new BigDecimal(var));
char ope = i < input.length() ? input.charAt(0) : 0;
if (ope == 0) return value;
int currOrder = order.getOrDefault(ope, -1);
BigDecimal result = null;
if (currOrder > 0)
result = calculate(input.substring(i + 1));
switch (currOrder) {
case '+':
return value.add(result);
case '-':
return value.subtract(result);
case '*':
return value.multiply(result);
case '/':
return value.divide(result, BigDecimal.ROUND_HALF_UP);
case '^':
// If pow of int BigDecimal can handle it
if (result.precision() == 0) return value.pow(result.intValue());
// Otherwise we gotta revert to power of doubles
return BigDecimal.valueOf(Math.pow(value.doubleValue(), result.doubleValue()));
}
return null;
}
示例13: testItem_0040
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0040()
{
BigDecimal alpha = new BigDecimal("1000").setScale(0);
BigDecimal beta = new BigDecimal("0.70").setScale(2);
BigDecimal gamma = alpha.multiply(beta);
gamma.setScale(1);
Assert.assertEquals("700.00", gamma.toString());
}
示例14: getBandValue
import java.math.BigDecimal; //导入方法依赖的package包/类
private BigDecimal getBandValue(SRVMBand band, int quantity) {
// The min{2,n} or min{4,n} part of the value function
int firstSummand = quantity > synergyThreshold.get(band.getName()) ? synergyThreshold.get(band.getName()) : quantity;
// The min{3/4, (n-1)/n} * syn_i(B)} or equivalent for other bands part
BigDecimal minFraction = new BigDecimal(firstSummand - 1).divide(new BigDecimal(firstSummand), CALCSCALE, RoundingMode.CEILING);
BigDecimal synergyFactor = intrabandSynergyFactors.get(band.getName());
BigDecimal secondSummand = minFraction.multiply(synergyFactor);
// The marginal decreasing third summand (max{0, ln{n-1)})
int toLog = quantity - (synergyThreshold.get(band.getName()) - 1);
BigDecimal thirdSummand;
if (toLog <= 0) {
thirdSummand = BigDecimal.ZERO;
} else {
double lnApproximation = Math.log(toLog);
BigDecimal ln = new BigDecimal(lnApproximation, new MathContext(CALCSCALE, RoundingMode.CEILING));
if (ln.compareTo(BigDecimal.ZERO) >= 0) {
thirdSummand = ln;
} else {
thirdSummand = BigDecimal.ZERO;
}
}
// Calculates product
BigDecimal firstFactor = new BigDecimal(firstSummand).add(secondSummand).add(thirdSummand);
BigDecimal baseValue = baseValues.get(band.getName());
// No need to take random influence and relative bidder strength into account. Is already included in baseValue;
return firstFactor.multiply(baseValue);
}
示例15: mult
import java.math.BigDecimal; //导入方法依赖的package包/类
private static BigDecimal mult(BigDecimal v, double mul) {
return v.multiply(new BigDecimal(mul));
}