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


Java BigDecimal.compareTo方法代碼示例

本文整理匯總了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;
        }
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:18,代碼來源:CategoryHolding.java

示例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;
}
 
開發者ID:x7-framework,項目名稱:x7,代碼行數:26,代碼來源:BeanUtilX.java

示例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);
	}
}
 
開發者ID:BSI-Business-Systems-Integration-AG,項目名稱:trading-network,代碼行數:19,代碼來源:TestOrderBook.java

示例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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:25,代碼來源:LandingpageServiceBeanLocal.java

示例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;
}
 
開發者ID:wangfei0904306,項目名稱:unionpay,代碼行數:12,代碼來源:UnionPaymentServiceImpl.java

示例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;
}
 
開發者ID:spectrumauctions,項目名稱:sats-opt,代碼行數:17,代碼來源:Scalor.java

示例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);
      }
    }
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:DoubleMathTest.java

示例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);
    }
}
 
開發者ID:mkeresztes,項目名稱:AndiCar,代碼行數:25,代碼來源:MileageEditFragment.java

示例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);
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:18,代碼來源:FieldReal.java

示例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;
    }
 
開發者ID:s-store,項目名稱:s-store,代碼行數:26,代碼來源:NumberType.java

示例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);
        }
    };
}
 
開發者ID:3wks,項目名稱:generator-thundr-gae-react,代碼行數:13,代碼來源:BigDecimalMatchers.java

示例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;
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:9,代碼來源:ArgComparator.java

示例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;
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:14,代碼來源:EqualsGreatThenAssertor.java

示例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;
}
 
開發者ID:spectrumauctions,項目名稱:sats-opt,代碼行數:16,代碼來源:SRVM_MIP.java

示例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;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:18,代碼來源:Math.java


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