本文整理汇总了Java中java.math.BigDecimal.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.compareTo方法的具体用法?Java BigDecimal.compareTo怎么用?Java BigDecimal.compareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.compareTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOffsetUnder
import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal getOffsetUnder(final CategoryHolding<?, ?> aHolding) {
BigDecimal retVal = BigMath.ZERO;
final Limit tmpLimit = aHolding.getLimit();
final BigDecimal tmpTarget = tmpLimit.getTarget();
final BigDecimal tmpPrecision = tmpLimit.getPrecision();
final BigDecimal tmpLower = BigFunction.SUBTRACT.invoke(tmpTarget, tmpPrecision);
final BigDecimal tmpWeight = aHolding.getWeight();
if (tmpWeight.compareTo(tmpLower) == -1) {
retVal = BigFunction.SUBTRACT.invoke(tmpLower, tmpWeight);
}
return retVal;
}
示例2: compare
import java.math.BigDecimal; //导入方法依赖的package包/类
private static <T> int compare(Class clz, String orderBy, boolean isAsc, T a, T b){
try {
int scValue = isAsc ? 1 : -1;
Field field = clz.getDeclaredField(orderBy);
field.setAccessible(true);
Object valueA = field.get(a);
Object valueB = field.get(b);
if (field.getType() == String.class){
int intA = valueA.toString().charAt(0);
int intB = valueB.toString().charAt(0);
if (intA > intB)
return 1 * scValue;
if (intA < intB)
return -1 * scValue;
return 0;
}else {
BigDecimal bdA = new BigDecimal(valueA.toString().toCharArray());
BigDecimal bdB = new BigDecimal(valueB.toString().toCharArray());
return bdA.compareTo(bdB) * scValue;
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
示例3: setUp
import java.math.BigDecimal; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() {
try {
String ownerAddress = Alice.ADDRESS;
String coinbaseAddress = Web3jHelper.getAccount(0);
BigDecimal coinbaseBalance = Web3jHelper.getBalance(coinbaseAddress, Unit.ETHER);
BigDecimal ownerBalance = Web3jHelper.getBalance(ownerAddress, Unit.ETHER);
System.out.println(String.format("Coinbase balance [Ether] %s with address %s", coinbaseBalance, coinbaseAddress));
System.out.println(String.format("Contact owner balence [Ether] %s with address %s", ownerBalance, ownerAddress));
if (ownerBalance.compareTo(BigDecimal.TEN) < 0) {
String txHash = Web3jHelper.transfer(coinbaseAddress, ownerAddress, 10, Unit.ETHER);
System.out.println(String.format("10 ether to owner sent, txHash=%s", txHash));
}
} catch (Exception e) {
throw new RuntimeException("Could not set up unit test", e);
}
}
示例4: compare
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public int compare(Product x, Product y) {
BigDecimal averageRatingX = new BigDecimal(0);
BigDecimal averageRatingY = new BigDecimal(0);
ProductFeedback xFeedback = x.getProductTemplate()
.getProductFeedback();
if (xFeedback != null) {
averageRatingX = xFeedback.getAverageRating();
}
ProductFeedback yFeedback = y.getProductTemplate()
.getProductFeedback();
if (yFeedback != null) {
averageRatingY = yFeedback.getAverageRating();
}
int compareTo = averageRatingY.compareTo(averageRatingX);
if (compareTo == 0) {
// on same ratings compare names
return nameComp.compare(x, y);
}
return compareTo;
}
示例5: 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;
}
示例6: calculateSVScalingFactor
import java.math.BigDecimal; //导入方法依赖的package包/类
private static double calculateSVScalingFactor(Collection<MRVMBidder> bidders) {
MRVMBidder biggestAlphaBidder = bidders.stream().max(Comparator.comparing(b -> b.getAlpha())).get();
MRVMRegionsMap.Region biggestRegion = bidders.stream().findAny().get().getWorld().getRegionsMap().getRegions().stream()
.max(Comparator.comparing(r -> r.getPopulation())).get();
BigDecimal biggestAlpha = biggestAlphaBidder.getAlpha();
BigDecimal biggestPopulation = BigDecimal.valueOf(biggestRegion.getPopulation());
BigDecimal biggestC = bidders.stream().findAny().get().getWorld().getMaximumRegionalCapacity();
BigDecimal securityBuffer = BigDecimal.valueOf(100000);
BigDecimal biggestSv = biggestAlpha.multiply(biggestPopulation).multiply(biggestC).add(securityBuffer);
BigDecimal MIP_MAX_VALUE = BigDecimal.valueOf(MIP.MAX_VALUE);
BigDecimal proposedScalingFactor = biggestSv.divide(MIP_MAX_VALUE, RoundingMode.HALF_DOWN);
if(proposedScalingFactor.compareTo(BigDecimal.ONE) <= 0){
return 1.;
}
return Math.round(proposedScalingFactor.doubleValue())+1;
}
示例7: testRoundIntegralDoubleToLong
import java.math.BigDecimal; //导入方法依赖的package包/类
@GwtIncompatible // DoubleMath.roundToLong(double, RoundingMode)
public void testRoundIntegralDoubleToLong() {
for (double d : INTEGRAL_DOUBLE_CANDIDATES) {
for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) {
BigDecimal expected = new BigDecimal(d).setScale(0, mode);
boolean isInBounds = expected.compareTo(MAX_LONG_AS_BIG_DECIMAL) <= 0
& expected.compareTo(MIN_LONG_AS_BIG_DECIMAL) >= 0;
try {
assertEquals(expected.longValue(), DoubleMath.roundToLong(d, mode));
assertTrue(isInBounds);
} catch (ArithmeticException e) {
assertFalse(isInBounds);
}
}
}
}
示例8: showReimbursementValue
import java.math.BigDecimal; //导入方法依赖的package包/类
@SuppressLint("SetTextI18n")
private void showReimbursementValue() {
if (!mReimbursementCanCalculated || mNewIndex == null) {
return;
}
try {
BigDecimal mReimbursementRate = mDbAdapter.getReimbursementRate(mCarId, mExpTypeId, mlDateTimeInMillis / 1000);
if (mReimbursementRate.compareTo(BigDecimal.ZERO) != 0 && mNewIndex.compareTo(mStartIndex) > 0) {
tvReimbursementValue.setVisibility(View.VISIBLE);
tvReimbursementValue.setText(mResource.getString(R.string.gen_reimbursement)
+ " "
+ Utils.numberToString((mNewIndex.subtract(mStartIndex)).multiply(mReimbursementRate), true, ConstantValues.DECIMALS_RATES,
ConstantValues.ROUNDING_MODE_RATES) + " " + mCarCurrencyCode);
}
else {
tvReimbursementValue.setVisibility(View.GONE);
}
}
catch (Exception e) {
mReimbursementCanCalculated = false; //avoid subsequent exceptions
tvReimbursementValue.setVisibility(View.GONE);
Utils.showReportableErrorDialog(getActivity(), getString(R.string.error_sorry), e.getMessage(), e);
}
}
示例9: compareTo
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public int compareTo(Field other) {
if (other == null || !(other instanceof FieldReal)) {
return 1;
}
FieldReal bOther = (FieldReal) other;
BigDecimal dec = this.valReal();
BigDecimal dec2 = bOther.valReal();
if (dec == null && dec2 == null)
return 0;
else if (dec2 == null)
return 1;
else if (dec == null)
return -1;
else
return dec.compareTo(dec2);
}
示例10: toDouble
import java.math.BigDecimal; //导入方法依赖的package包/类
public static double toDouble(Object a) {
double value;
if (a instanceof java.lang.Double) {
return ((Double) a).doubleValue();
} else if (a instanceof BigDecimal) {
BigDecimal bd = (BigDecimal) a;
value = bd.doubleValue();
int signum = bd.signum();
BigDecimal bdd = new BigDecimal(value + signum);
if (bdd.compareTo(bd) != signum) {
throw Error.error(ErrorCode.X_22003);
}
} else if (a instanceof Number) {
value = ((Number) a).doubleValue();
} else {
throw Error.error(ErrorCode.X_22501);
}
return value;
}
示例11: lessThan
import java.math.BigDecimal; //导入方法依赖的package包/类
public static Matcher<BigDecimal> lessThan(final BigDecimal bigDecimal) {
return new BaseMatcher<BigDecimal>() {
public boolean matches(Object o) {
BigDecimal actual = (BigDecimal) o;
return actual != null && actual.compareTo(bigDecimal) < 0;
}
public void describeTo(Description description) {
description.appendText("value less than " + bigDecimal);
}
};
}
示例12: compare
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public int compare(ArgComparator ac) {
BigDecimal val1 = ac.a.valDecimal();
BigDecimal val2 = ac.b.valDecimal();
if (ac.a.isNull() || ac.b.isNull())
return (ac.a.isNull() && ac.b.isNull()) ? 1 : 0;
return (val1.compareTo(val2) == 0) ? 1 : 0;
}
示例13: eval
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public boolean eval(Object left, Object right) {
if(left==null || right==null){
return false;
}
if(StringUtils.isBlank(left.toString()) || StringUtils.isBlank(right.toString())){
return false;
}
BigDecimal leftObj=Utils.toBigDecimal(left);
right=buildObject(right);
BigDecimal rightObj=Utils.toBigDecimal(right);
return leftObj.compareTo(rightObj)>-1;
}
示例14: biggestUnscaledPossibleValue
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Returns the biggest possible value any of the passed bidders can have
*
* @return
*/
public static BigDecimal biggestUnscaledPossibleValue(Collection<SRVMBidder> bidders) {
BigDecimal biggestValue = BigDecimal.ZERO;
for (SRVMBidder bidder : bidders) {
BigDecimal val = bidder.calculateValue(new Bundle<>(bidder.getWorld().getLicenses()));
if (val.compareTo(biggestValue) > 0) {
biggestValue = val;
}
}
return biggestValue;
}
示例15: pow
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* y raised to the x power
*/
public static BigDecimal pow( BigDecimal y, BigDecimal x ) {
if ( x.compareTo( new BigDecimal( "1" ) ) <= 0 ) {
throw new ArithmeticException( "Powers of BigDecimals must be integers greater than 1" );
}
String exp = x.toString();
if ( exp.indexOf( "." ) > 0 )
exp = exp.substring( 0, exp.indexOf( "." ) );
BigInteger e = new BigInteger( exp );
BigDecimal z = new BigDecimal( y.toString() );
for ( ;e.compareTo( BigInteger.ONE ) > 0; e = e.subtract( BigInteger.ONE ) ) {
y = y.multiply( z );
}
return y;
}