List of usage examples for java.math BigDecimal ROUND_UP
int ROUND_UP
To view the source code for java.math BigDecimal ROUND_UP.
Click Source Link
From source file:com.ylife.shoppingcart.service.impl.ShoppingCartServiceImpl.java
/** * /*from w w w.j a va 2 s. co m*/ * * @param motheds * @param fe * @param num * @param weight * @return BigDecimal */ public BigDecimal computeFreight(String motheds, FreightExpress fe, Integer num, BigDecimal weight) { BigDecimal price = new BigDecimal(0); if (num == 0) { return price; } // if ("0".equals(motheds)) { // ? if (num < Integer.parseInt(fe.getExpressStart().toString())) { // = + -* int a = 0; BigDecimal temp = fe.getExpressPostageplus().multiply(new BigDecimal(a)); price = fe.getExpressPostage().add(temp); } else { // = + -* int a = num - Integer.parseInt(fe.getExpressStart().toString()); BigDecimal temp = fe.getExpressPostageplus().multiply( (new BigDecimal(a)).divide(new BigDecimal(fe.getExpressPlusN1()), 0, BigDecimal.ROUND_UP)); price = fe.getExpressPostage().add(temp); } return price; } else { // ?? if (weight.compareTo(new BigDecimal(fe.getExpressStart())) == -1) { // ? = ? + ?-?*? BigDecimal a = new BigDecimal(0); BigDecimal temp = fe.getExpressPostageplus().multiply(a); price = fe.getExpressPostage().add(temp); } else { // ? = ? + ?-?*? BigDecimal a = weight.subtract(new BigDecimal(fe.getExpressStart())); BigDecimal temp = fe.getExpressPostageplus() .multiply(a.divide(new BigDecimal(fe.getExpressPlusN1()), 0, BigDecimal.ROUND_UP)); price = fe.getExpressPostage().add(temp); } return price; } }
From source file:com.ylife.shoppingcart.service.impl.ShoppingCartServiceImpl.java
/** * //from ww w . j av a 2s.com * * @param motheds * @param frall * @param num * @param weight * @return BigDecimal */ public BigDecimal computeFreightAll(String motheds, FreightExpressAll frall, Integer num, BigDecimal weight) { BigDecimal price = new BigDecimal(0); if (num == 0) { return price; } // if ("0".equals(motheds)) { // ? if (num < Integer.parseInt(frall.getExpressStart().toString())) { // = + -* int a = 0; BigDecimal temp = frall.getExpressPostageplus().multiply(new BigDecimal(a)); price = frall.getExpressPostage().add(temp); } else { // = + -* int a = num - Integer.parseInt(frall.getExpressStart().toString()); BigDecimal temp = frall.getExpressPostageplus().multiply((new BigDecimal(a)) .divide(new BigDecimal(frall.getExpressPlusN1()), 0, BigDecimal.ROUND_UP)); price = frall.getExpressPostage().add(temp); } return price; } else { // ?? if (weight.compareTo(new BigDecimal(frall.getExpressStart())) == -1) { // ? = ? + ?-?*? BigDecimal a = new BigDecimal(0); BigDecimal temp = frall.getExpressPostageplus().multiply(a); price = frall.getExpressPostage().add(temp); } else { // ? = ? + ?-?*? BigDecimal a = weight.subtract(new BigDecimal(frall.getExpressStart())); BigDecimal temp = frall.getExpressPostageplus() .multiply(a.divide(new BigDecimal(frall.getExpressPlusN1()), 0, BigDecimal.ROUND_UP)); price = frall.getExpressPostage().add(temp); } return price; } }
From source file:org.egov.collection.web.actions.receipts.ReceiptAction.java
/** * This method create a new receipt header object with details contained in given receipt header object. * @param oldReceiptHeader the instance of <code>ReceiptHeader</code> whose data is to be copied *//* w w w .j a va 2 s . c o m*/ private void populateReceiptModelWithExistingReceiptInfo(final ReceiptHeader oldReceiptHeader) { totalAmntToBeCollected = BigDecimal.ZERO; receiptHeader = new ReceiptHeader(oldReceiptHeader.getReferencenumber(), oldReceiptHeader.getReferencedate(), oldReceiptHeader.getConsumerCode(), oldReceiptHeader.getReferenceDesc(), oldReceiptHeader.getTotalAmount(), oldReceiptHeader.getMinimumAmount(), oldReceiptHeader.getPartPaymentAllowed(), oldReceiptHeader.getOverrideAccountHeads(), oldReceiptHeader.getCallbackForApportioning(), oldReceiptHeader.getDisplayMsg(), oldReceiptHeader.getService(), oldReceiptHeader.getCollModesNotAllwd(), oldReceiptHeader.getPayeeName(), oldReceiptHeader.getPayeeAddress(), oldReceiptHeader.getPayeeEmail(), oldReceiptHeader.getConsumerType()); if (oldReceiptHeader.getCollModesNotAllwd() != null) setCollectionModesNotAllowed(Arrays.asList(oldReceiptHeader.getCollModesNotAllwd().split(","))); setOverrideAccountHeads(oldReceiptHeader.getOverrideAccountHeads()); setPartPaymentAllowed(oldReceiptHeader.getPartPaymentAllowed()); setServiceName(oldReceiptHeader.getService().getName()); receiptHeader.setReceiptMisc(new ReceiptMisc(oldReceiptHeader.getReceiptMisc().getBoundary(), oldReceiptHeader.getReceiptMisc().getFund(), oldReceiptHeader.getReceiptMisc().getIdFunctionary(), oldReceiptHeader.getReceiptMisc().getFundsource(), oldReceiptHeader.getReceiptMisc().getDepartment(), receiptHeader, oldReceiptHeader.getReceiptMisc().getScheme(), oldReceiptHeader.getReceiptMisc().getSubscheme(), null)); receiptHeader.setLocation(oldReceiptHeader.getLocation()); bankCOAList = chartOfAccountsDAO.getBankChartofAccountCodeList(); for (final ReceiptDetail oldDetail : oldReceiptHeader.getReceiptDetails()) // debit account heads for revenue accounts should not be considered if (oldDetail.getOrdernumber() != null && !FinancialsUtil .isRevenueAccountHead(oldDetail.getAccounthead(), bankCOAList, persistenceService)) { final ReceiptDetail receiptDetail = new ReceiptDetail(oldDetail.getAccounthead(), oldDetail.getFunction(), oldDetail.getCramount(), oldDetail.getDramount(), oldDetail.getCramount(), oldDetail.getOrdernumber(), oldDetail.getDescription(), oldDetail.getIsActualDemand(), receiptHeader, oldDetail.getPurpose(), oldDetail.getGroupId()); receiptDetail.setCramountToBePaid(oldDetail.getCramountToBePaid()); receiptDetail.setCramount(oldDetail.getCramount()); if (oldDetail.getAccountPayeeDetails() != null) for (final AccountPayeeDetail oldAccountPayeeDetail : oldDetail.getAccountPayeeDetails()) { final AccountPayeeDetail accountPayeeDetail = new AccountPayeeDetail( oldAccountPayeeDetail.getAccountDetailType(), oldAccountPayeeDetail.getAccountDetailKey(), oldAccountPayeeDetail.getAmount(), receiptDetail); receiptDetail.addAccountPayeeDetail(accountPayeeDetail); } if (oldDetail.getIsActualDemand()) totalAmntToBeCollected = totalAmntToBeCollected.add(oldDetail.getCramountToBePaid()) .subtract(oldDetail.getDramount()) .setScale(CollectionConstants.AMOUNT_PRECISION_DEFAULT, BigDecimal.ROUND_UP); setTotalAmntToBeCollected(totalAmntToBeCollected); receiptHeader.addReceiptDetail(receiptDetail); } if (oldReceiptHeader.getReceipttype() == CollectionConstants.RECEIPT_TYPE_ADHOC) { loadReceiptDetails(receiptHeader); createMisc(); if (oldReceiptHeader.getVoucherNum() != null) setVoucherNum(voucherNum); } setReceiptDetailList(new ArrayList<ReceiptDetail>(receiptHeader.getReceiptDetails())); setCollModesNotAllowedForRemitReceipt(oldReceiptHeader.getCollModesNotAllwd()); }
From source file:org.pentaho.di.core.ConstTest.java
@Test public void testRound() { assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(1.0, Const.round(1.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(1.2, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(1.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(1.0, Const.round(1.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1.0, Const.round(1.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(1.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(1.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(2.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(3.0, Const.round(2.2, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(3.0, Const.round(2.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(2.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(3.0, Const.round(2.5, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(3.0, Const.round(2.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(3.0, Const.round(2.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(3.0, Const.round(2.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(3.0, Const.round(2.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1.0, Const.round(-1.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-1.2, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-1.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1.0, Const.round(-1.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1.0, Const.round(-1.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1.0, Const.round(-1.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-1.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-2.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(-3.0, Const.round(-2.2, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(-3.0, Const.round(-2.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-2.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(-3.0, Const.round(-2.5, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(-3.0, Const.round(-2.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-3.0, Const.round(-2.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-2.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-3.0, Const.round(-2.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.010, Const.round(0.010, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.012, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.012, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.010, Const.round(0.012, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.015, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.015, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.010, Const.round(0.015, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.015, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.017, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.017, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.017, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.020, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.030, Const.round(0.022, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.030, Const.round(0.022, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.022, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.030, Const.round(0.025, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.030, Const.round(0.025, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.030, Const.round(0.025, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.030, Const.round(0.025, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.027, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.027, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.030, Const.round(0.027, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.010, Const.round(-0.010, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.012, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.012, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.010, Const.round(-0.012, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.015, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.015, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.010, Const.round(-0.015, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.010, Const.round(-0.015, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.017, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.017, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.017, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.020, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.030, Const.round(-0.022, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.030, Const.round(-0.022, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.022, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.030, Const.round(-0.025, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.030, Const.round(-0.025, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.030, Const.round(-0.025, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.025, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.027, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.027, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.030, Const.round(-0.027, 2, Const.ROUND_HALF_CEILING)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100.0, Const.round(100.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(120.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(120.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100.0, Const.round(120.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(150.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(150.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100.0, Const.round(150.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(150.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(170.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(170.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(170.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(200.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(300.0, Const.round(220.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(300.0, Const.round(220.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(220.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(300.0, Const.round(250.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(300.0, Const.round(250.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300.0, Const.round(250.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300.0, Const.round(250.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(270.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(270.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300.0, Const.round(270.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100.0, Const.round(-100.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-120.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-120.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100.0, Const.round(-120.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-150.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-150.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100.0, Const.round(-150.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100.0, Const.round(-150.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-170.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-170.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-170.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-200.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300.0, Const.round(-220.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300.0, Const.round(-220.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-220.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300.0, Const.round(-250.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300.0, Const.round(-250.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300.0, Const.round(-250.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-250.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-270.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-270.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-300.0, Const.round(-270.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(Double.NaN, Const.round(Double.NaN, 0, BigDecimal.ROUND_UP)); assertEquals(Double.NEGATIVE_INFINITY, Const.round(Double.NEGATIVE_INFINITY, 0, BigDecimal.ROUND_UP)); assertEquals(Double.POSITIVE_INFINITY, Const.round(Double.POSITIVE_INFINITY, 0, BigDecimal.ROUND_UP)); }
From source file:org.pentaho.di.core.ConstTest.java
@Test public void testRound_Long() { assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_UP)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_DOWN)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_CEILING)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(1L, Const.round(1L, 0, Const.ROUND_HALF_CEILING)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_UP)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_DOWN)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_CEILING)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2L, Const.round(2L, 0, Const.ROUND_HALF_CEILING)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_UP)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_CEILING)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1L, Const.round(-1L, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_UP)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2L, Const.round(-2L, 0, Const.ROUND_HALF_CEILING)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_DOWN)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100L, Const.round(100L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(120L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(120L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100L, Const.round(120L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(150L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(150L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100L, Const.round(150L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(150L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(170L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(170L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(170L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(200L, -2, Const.ROUND_HALF_CEILING)); assertEquals(300L, Const.round(220L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_DOWN)); assertEquals(300L, Const.round(220L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(220L, -2, Const.ROUND_HALF_CEILING)); assertEquals(300L, Const.round(250L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_DOWN)); assertEquals(300L, Const.round(250L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300L, Const.round(250L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300L, Const.round(250L, -2, Const.ROUND_HALF_CEILING)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(270L, -2, BigDecimal.ROUND_DOWN)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(270L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300L, Const.round(270L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100L, Const.round(-100L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-120L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-120L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100L, Const.round(-120L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-150L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-150L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100L, Const.round(-150L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100L, Const.round(-150L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-170L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-170L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-170L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-200L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300L, Const.round(-220L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300L, Const.round(-220L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-220L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300L, Const.round(-250L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300L, Const.round(-250L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300L, Const.round(-250L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-250L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-270L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-270L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-300L, Const.round(-270L, -2, Const.ROUND_HALF_CEILING)); }
From source file:org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO.java
/** * @param apiIdentifier API Identifier/*from w w w . java 2 s. c o m*/ * @throws APIManagementException if failed to add Application */ public float getAverageRating(APIIdentifier apiIdentifier, Connection conn) throws APIManagementException, SQLException { PreparedStatement ps = null; ResultSet rs = null; float avrRating = 0; try { //Get API Id int apiId; apiId = getAPIID(apiIdentifier, conn); if (apiId == -1) { String msg = "Could not load API record for: " + apiIdentifier.getApiName(); log.error(msg); return Float.NEGATIVE_INFINITY; } //This query to update the AM_API_RATINGS table String sqlQuery = SQLConstants.GET_AVERAGE_RATING_SQL; ps = conn.prepareStatement(sqlQuery); ps.setInt(1, apiId); rs = ps.executeQuery(); while (rs.next()) { avrRating = rs.getFloat("RATING"); } } catch (SQLException e) { handleException("Failed to add Application", e); } finally { APIMgtDBUtil.closeAllConnections(ps, null, rs); } BigDecimal decimal = new BigDecimal(avrRating); return Float.parseFloat(decimal.setScale(1, BigDecimal.ROUND_UP).toString()); }