Example usage for java.math BigDecimal ROUND_HALF_EVEN

List of usage examples for java.math BigDecimal ROUND_HALF_EVEN

Introduction

In this page you can find the example usage for java.math BigDecimal ROUND_HALF_EVEN.

Prototype

int ROUND_HALF_EVEN

To view the source code for java.math BigDecimal ROUND_HALF_EVEN.

Click Source Link

Document

Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.

Usage

From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java

@Override
@Transactional(readOnly = true)/*from  w w  w . j  a  va 2 s . co m*/
public Map<String, Object> getShopDetail(String shopNo, String memberNo) throws Exception {
    String sql = "select " + " tsi.shop_name shopName," + " tsi.status status," + " tsi.shop_logo shopLogo,"
            + " tsi.shop_type_no shopTypeNo," + " tsi.shop_address address," + " tsi.shop_summary summary,"//
            + " tsi.phone phone,"//?
            + " tsi.merch_no memberNo,"//?
            + " tsi.begin_time beginTime,"//?
            + " tsi.end_time endTime,"//??
            + " tsi.shop_sign shopSign,"//
            + " tsi.sell_scope sellScope,"//??
            + " tsi.delivery_type deliveryType,"//??
            + " ifnull(tsi.delivery_fee,0) deliveryFee,"//?
            + " tsi.company_name companyName,"//???
            + " tsi.license_regist_no licenseRegistNo,"//??
            + " if(tsi.is_recommend is null,'0',tsi.is_recommend) isRecommend "
            + " from tbl_shop_info tsi where tsi.shop_no = :shopNo";
    Query query = shopDao.createSQLQuery(sql);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    Map<String, Object> map = (Map<String, Object>) query.uniqueResult();
    String sqlComment = "select avg(tcc.service_grade) serviceGrade,avg(tcc.delivery_grade) deliveryGrade "
            + " from tbl_commodity_comment tcc where tcc.shop_no=:shopNo";
    query = shopDao.createSQLQuery(sqlComment);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    if (map != null) {
        Map<String, Object> mapComment = (Map<String, Object>) query.uniqueResult();
        if (mapComment != null) {
            Double servGrade = mapComment.get("serviceGrade") == null ? 0
                    : Double.valueOf(mapComment.get("serviceGrade").toString());
            BigDecimal serviceGrade = new BigDecimal(servGrade);
            serviceGrade = serviceGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN);
            map.put("serviceGrade", serviceGrade.doubleValue());
            Double delGrade = mapComment.get("deliveryGrade") == null ? 0
                    : Double.valueOf(mapComment.get("deliveryGrade").toString());
            BigDecimal deliveryGrade = new BigDecimal(delGrade);
            deliveryGrade = deliveryGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN);
            map.put("deliveryGrade", deliveryGrade.doubleValue());
        } else {
            map.put("serviceGrade", 0);
            map.put("deliveryGrade", 0);
        }
    }

    if (map != null) {
        map.put("promotions", promotionService.getPromotionByShopNo(shopNo, memberNo));
    }
    String sqlProduct = "select IF(tp.prod_name is null,'',tp.prod_name) prodName," + "tp.model model,"
            + " IF(tp.default_pic is null,'',tp.default_pic) prodPic," + " tp.price prodPrice,"
            + " tp.is_groupbuy isGroupbuy," + " tp.prod_no prodNo," + " tp.sort sort,"
            + " ifnull(tp.stock,0) stock," + " ifnull(tp.stock_preemption,0) stockPreemption,"
            + " IF(tp.sell_num is null,0,tp.sell_num) sellNum "
            + " from tbl_product tp left join tbl_commodity tc on tc.commo_no = tp.commo_no"
            + " where tc.seller_no = :shopNo and tc.publish_state ='1' and (tp.is_groupbuy is null or tp.is_groupbuy='1') and tp.delete_flag ='0' order by ifnull(tp.sort,2147483647) asc,tc.publish_time desc";
    query = productDao.createSQLQuery(sqlProduct);
    //      query.setMaxResults(10);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> prods = query.list();
    if (prods != null && !prods.isEmpty()) {
        for (Map<String, Object> r : prods) {
            //????+
            String prodName = (String) (r.get("prodName") == null ? "" : r.get("prodName"));
            String model = (String) (r.get("model") == null ? "" : r.get("model"));
            if (model != null && !model.equals("")) {
                r.put("prodName", prodName + "(" + model + ")");
            }
        }
    }

    if (map != null) {
        map.put("products", prods);
    }
    String sqlGroupBuyProduct = "select IF(tp.prod_name is null,'',tp.prod_name) prodName," + "tp.model model,"
            + " IF(tp.default_pic is null,'',tp.default_pic) prodPic," + " tp.price prodPrice,"
            + " tp.is_groupbuy isGroupbuy," + " tp.prod_no prodNo," + " tp.sort sort,"
            + " ifnull(tp.stock,0) stock," + " tpromotion.promotion_no promotionNo,"
            + " tpromotion.discount_amount groupbuyPrice," + " tpromotion.end_time endTime,"
            + " ifnull(tp.stock_preemption,0) stockPreemption,"
            + " IF(tp.sell_num is null,0,tp.sell_num) sellNum "
            + " from tbl_product tp left join tbl_commodity tc on tc.commo_no = tp.commo_no"
            + " left join tbl_promotion tpromotion on tpromotion.ref_commo_no = tc.commo_no"
            + " where tc.seller_no = :shopNo and tc.publish_state ='1'  and tp.is_groupbuy='2' and tpromotion.status='2' "
            + " and now() between tpromotion.start_time and tpromotion.end_time "
            + " and tpromotion.delete_flag ='0' and tp.delete_flag ='0' order by ifnull(tp.sort,2147483647) asc,tc.publish_time desc";
    query = productDao.createSQLQuery(sqlGroupBuyProduct);
    //      query.setMaxResults(10);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> groupBuyProds = query.list();
    if (groupBuyProds != null && !groupBuyProds.isEmpty()) {
        for (Map<String, Object> gpd : groupBuyProds) {
            //????+
            String prodName = (String) (gpd.get("prodName") == null ? "" : gpd.get("prodName"));
            String model = (String) (gpd.get("model") == null ? "" : gpd.get("model"));
            if (model != null && !model.equals("")) {
                gpd.put("prodName", prodName + "(" + model + ")");
            }

            String promotionNo = (String) gpd.get("promotionNo");
            Order buyerOrder = this.getOrderByBuyer(promotionNo, memberNo);
            if (buyerOrder != null) {
                if (buyerOrder.getBasicState().equals(OrderConstants.BASIC_STATE_WAITING_PAY))
                    gpd.put("buyed", "1");//
                else
                    gpd.put("buyed", "2");//
            } else {
                gpd.put("buyed", "0");
            }
        }
    }
    if (map != null) {
        map.put("groupBuyProds", groupBuyProds);
    }

    String sqlCollect = "select * from tbl_shop_collect tsc where tsc.shop_no = :shopNo ";
    Query queryC = shopCollectDao.createSQLQuery(sqlCollect);
    queryC.setParameter("shopNo", shopNo);
    List listCollect = queryC.list();
    if (map != null) {
        map.put("collectNum", listCollect == null ? 0 : listCollect.size());
    }
    //      Query queryCollect = shopCollectDao.createSQLQuery(sqlCollect+"and tsc.member_no = :memberNo");
    //      queryCollect.setParameter("shopNo", shopNo);
    //      queryCollect.setParameter("memberNo", memberNo);
    //      List list = queryCollect.list();
    //      map.put("isCollect", list!=null&&!list.isEmpty()?"1":"0");
    String sqlCat = "select tc.cat_no catNo," + " IF(tcat.cat_name is null,'',tcat.cat_name) catName "
            + " from tbl_commodity tc " + " left join tbl_commo_category tcat "
            + " on tc.cat_no = tcat.cat_no where seller_no = :shopNo group by(tcat.cat_no)";
    query = commodityCatDao.createSQLQuery(sqlCat);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> cats = query.list();
    if (map != null) {
        map.put("cats", cats);
    }
    if (map != null && map.get("shopSign") == null) {
        map.put("shopSign", "");
    }
    return map;
}

From source file:org.hyperic.hq.measurement.server.session.DataManagerImpl.java

/**
 * Convert a decimal value to something suitable for being thrown into the
 * database with a NUMERIC(24,5) definition
 *//*from w  w  w .j  av  a2  s .  c  o  m*/
private BigDecimal getDecimalInRange(BigDecimal val, Integer metricId) {
    val = val.setScale(5, BigDecimal.ROUND_HALF_EVEN);
    if (val.compareTo(MAX_DB_NUMBER) == 1) {
        log.warn("Value [" + val + "] for metric id=" + metricId
                + "is too big to put into the DB.  Truncating to [" + MAX_DB_NUMBER + "]");
        return MAX_DB_NUMBER;
    }

    return val;
}

From source file:org.pentaho.di.core.ConstTest.java

@Test
public void testRound_BigDecimal() {
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.010"),
            Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.010"),
            Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.010"),
            Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.010"),
            Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.010"),
            Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.015"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.020"),
            Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-0.030"),
            Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-0.030"),
            Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-100.0"),
            Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-100.0"),
            Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-100.0"),
            Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-100.0"),
            Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-100.0"),
            Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-150.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-200.0"),
            Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, Const.ROUND_HALF_CEILING));

    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_UP));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_DOWN));
    assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_CEILING));
    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_FLOOR));
    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_HALF_UP));
    assertEquals(new BigDecimal("-300.0"),
            Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_HALF_DOWN));
    assertEquals(new BigDecimal("-300.0"),
            Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_HALF_EVEN));
    assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, Const.ROUND_HALF_CEILING));
}

From source file:org.pentaho.di.core.row.ValueDataUtil.java

/**
 * Rounding with decimal places (using default rounding method ROUND_HALF_EVEN)
 *
 * @param metaA/*  w w  w. j  a  v  a  2s  . c  o  m*/
 *          Metadata of value to round
 * @param dataA
 *          Value to round
 * @param metaB
 *          Metadata of decimal places
 * @param dataB
 *          decimal places
 * @return The rounded value
 * @throws KettleValueException
 */
public static Object round(ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB)
        throws KettleValueException {
    return round(metaA, dataA, metaB, dataB, BigDecimal.ROUND_HALF_EVEN);
}

From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java

@Override
@Transactional// ww  w  . j  ava2  s.  c o m
public Map<String, Object> getShopDetailNoUserId(String shopNo, String memberNo) throws Exception {
    String sql = "select " + " tsi.shop_name shopName," + " tsi.status status," + " tsi.shop_logo shopLogo,"
            + " tsi.shop_address address," + " tsi.shop_summary summary,"//
            + " tsi.phone phone,"//?
            + " tsi.merch_no memberNo,"//?
            + " tsi.begin_time beginTime,"//?
            + " tsi.end_time endTime,"//??
            + " tsi.shop_sign shopSign,"//
            + " tsi.sell_scope sellScope,"//??
            + " tsi.delivery_type deliveryType,"//??
            + " tsi.company_name companyName,"//???
            + " tsi.license_regist_no licenseRegistNo,"//??
            + " if(tsi.is_recommend is null,'0',tsi.is_recommend) isRecommend "
            + " from tbl_shop_info tsi where tsi.shop_no = :shopNo";
    Query query = shopDao.createSQLQuery(sql);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    Map<String, Object> map = (Map<String, Object>) query.uniqueResult();
    String sqlComment = "select avg(tcc.service_grade) serviceGrade,avg(tcc.delivery_grade) deliveryGrade "
            + " from tbl_commodity_comment tcc where tcc.shop_no=:shopNo";
    query = shopDao.createSQLQuery(sqlComment);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    if (map != null) {
        Map<String, Object> mapComment = (Map<String, Object>) query.uniqueResult();
        if (mapComment != null) {
            Double servGrade = mapComment.get("serviceGrade") == null ? 0
                    : Double.valueOf(mapComment.get("serviceGrade").toString());
            BigDecimal serviceGrade = new BigDecimal(servGrade);
            serviceGrade = serviceGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN);
            map.put("serviceGrade", serviceGrade.doubleValue());
            Double delGrade = mapComment.get("deliveryGrade") == null ? 0
                    : Double.valueOf(mapComment.get("deliveryGrade").toString());
            BigDecimal deliveryGrade = new BigDecimal(delGrade);
            deliveryGrade = deliveryGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN);
            map.put("deliveryGrade", deliveryGrade.doubleValue());
        } else {
            map.put("serviceGrade", 0);
            map.put("deliveryGrade", 0);
        }
    }

    if (map != null) {
        map.put("promotions", "");
    }
    String sqlProduct = "select IF(tp.prod_name is null,'',tp.prod_name) prodName,"
            + " IF(tp.default_pic is null,'',tp.default_pic) prodPic," + " tp.price prodPrice,"
            + " tp.prod_no prodNo," + " tp.sort sort," + " ifnull(tp.stock,0) stock,"
            + " ifnull(tp.stock_preemption,0) stockPreemption,"
            + " IF(tp.sell_num is null,0,tp.sell_num) sellNum "
            + " from tbl_product tp left join tbl_commodity tc on tc.commo_no = tp.commo_no"
            + " where tc.seller_no = :shopNo and tc.publish_state ='1' and (tp.is_groupbuy is null or tp.is_groupbuy='1') and tp.delete_flag ='0' order by ifnull(tp.sort,2147483647) asc,tc.publish_time desc";
    query = productDao.createSQLQuery(sqlProduct);
    //      query.setMaxResults(10);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> prods = query.list();
    if (map != null) {
        map.put("products", prods);
    }
    String sqlGroupBuyProduct = "select IF(tp.prod_name is null,'',tp.prod_name) prodName,"
            + " IF(tp.default_pic is null,'',tp.default_pic) prodPic," + " tp.price prodPrice,"
            + " tp.prod_no prodNo," + " tp.sort sort," + " ifnull(tp.stock,0) stock,"
            + " tpromotion.discount_amount groupbuyPrice," + " tpromotion.end_time endTime,"
            + " ifnull(tp.stock_preemption,0) stockPreemption,"
            + " IF(tp.sell_num is null,0,tp.sell_num) sellNum "
            + " from tbl_product tp left join tbl_commodity tc on tc.commo_no = tp.commo_no"
            + " left join tbl_promotion tpromotion on tpromotion.ref_commo_no = tc.commo_no"
            + " where tc.seller_no = :shopNo and tc.publish_state ='1'  and tp.is_groupbuy='2' and tpromotion.status='2' "
            + " and now() between tpromotion.start_time and tpromotion.end_time "
            + " and tpromotion.delete_flag ='0' and tp.delete_flag ='0' order by ifnull(tp.sort,2147483647) asc,tc.publish_time desc";
    query = productDao.createSQLQuery(sqlGroupBuyProduct);
    //      query.setMaxResults(10);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> groupBuyProds = query.list();
    if (map != null) {
        map.put("groupBuyProds", groupBuyProds);
    }
    String sqlCollect = "select * from tbl_shop_collect tsc where tsc.shop_no = :shopNo ";
    Query queryC = shopCollectDao.createSQLQuery(sqlCollect);
    queryC.setParameter("shopNo", shopNo);
    List listCollect = queryC.list();
    if (map != null) {
        map.put("collectNum", listCollect == null ? 0 : listCollect.size());
    }
    //      Query queryCollect = shopCollectDao.createSQLQuery(sqlCollect+"and tsc.member_no = :memberNo");
    //      queryCollect.setParameter("shopNo", shopNo);
    //      queryCollect.setParameter("memberNo", memberNo);
    //      List list = queryCollect.list();
    //      map.put("isCollect", list!=null&&!list.isEmpty()?"1":"0");
    String sqlCat = "select tc.cat_no catNo," + " IF(tcat.cat_name is null,'',tcat.cat_name) catName "
            + " from tbl_commodity tc " + " left join tbl_commo_category tcat "
            + " on tc.cat_no = tcat.cat_no where seller_no = :shopNo group by(tcat.cat_no)";
    query = commodityCatDao.createSQLQuery(sqlCat);
    query.setParameter("shopNo", shopNo);
    query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<Map<String, Object>> cats = query.list();
    if (map != null) {
        map.put("cats", cats);
    }
    return map;
}

From source file:org.egov.ptis.domain.service.report.ReportService.java

private void buildCollectionReportForUlbWiseDCb(
        final List<BillCollectorDailyCollectionReportResult> listBcPayment) {
    Double percentage = 0.0;/*from   w w  w.  j a v  a  2  s. c o  m*/
    for (final BillCollectorDailyCollectionReportResult bcResult : listBcPayment) {

        if (bcResult.getArrears_demand() == null)
            bcResult.setArrears_demand(0.0);
        if (bcResult.getCurrent_demand() == null)
            bcResult.setCurrent_demand(0.0);
        if (bcResult.getArrears_penalty() == null)
            bcResult.setArrears_penalty(0.0);
        if (bcResult.getCurrent_penalty() == null)
            bcResult.setCurrent_penalty(0.0);
        if (bcResult.getTotalaccessments() == null)
            bcResult.setTotalaccessments(BigDecimal.valueOf(0));

        bcResult.setTarget_total_demand(bcResult.getArrears_demand() + bcResult.getCurrent_demand());
        bcResult.setTarget_total_demandInterest(bcResult.getArrears_penalty() + bcResult.getCurrent_penalty());

        if (bcResult.getCurrent_demand_collection() == null)
            bcResult.setCurrent_demand_collection(0.0);
        if (bcResult.getArrears_demand_collection() == null)
            bcResult.setArrears_demand_collection(0.0);
        if (bcResult.getCurrent_penalty_collection() == null)
            bcResult.setCurrent_penalty_collection(0.0);
        if (bcResult.getArrears_penalty_collection() == null)
            bcResult.setArrears_penalty_collection(0.0);

        bcResult.setCummulative_total_Collection(
                bcResult.getCurrent_demand_collection() + bcResult.getArrears_demand_collection());
        bcResult.setCummulative_total_CollectionInterest(
                bcResult.getCurrent_penalty_collection() + bcResult.getArrears_penalty_collection());

        if (bcResult.getTarget_total_demand() != 0.0) {
            percentage = bcResult.getCummulative_total_Collection() * 100 / bcResult.getTarget_total_demand();
            bcResult.setCummulative_total_CollectionPercentage(
                    BigDecimal.valueOf(percentage.isNaN() ? 0.0 : percentage));
            percentage = (bcResult.getCummulative_total_Collection()
                    + bcResult.getCummulative_total_CollectionInterest()) * 100
                    / bcResult.getTarget_total_demand();
            bcResult.setCummulative_total_CollectionInterestPercentage(
                    BigDecimal.valueOf(percentage.isNaN() ? 0.0 : percentage));
        } else {
            bcResult.setCummulative_total_CollectionPercentage(ZERO);
            bcResult.setCummulative_total_CollectionInterestPercentage(ZERO);
        }

        bcResult.setBalance_arrearTax(bcResult.getArrears_demand() - bcResult.getArrears_demand_collection());
        bcResult.setBalance_arrearInterest(
                bcResult.getArrears_penalty() - bcResult.getArrears_penalty_collection());
        bcResult.setBalance_currentTax(bcResult.getCurrent_demand() - bcResult.getCurrent_demand_collection());
        bcResult.setBalance_currentInterest(
                bcResult.getCurrent_penalty() - bcResult.getCurrent_penalty_collection());
        bcResult.setBalance_total(
                bcResult.getTarget_total_demand() - bcResult.getCummulative_total_Collection());
        bcResult.setBalance_totalInterest(
                bcResult.getTarget_total_demandInterest() - bcResult.getCummulative_total_CollectionInterest());
    }

    for (final BillCollectorDailyCollectionReportResult bcResult : listBcPayment) {

        bcResult.setBalance_arrearTax(formatAmt(bcResult.getBalance_arrearTax()).doubleValue());
        bcResult.setBalance_arrearInterest(formatAmt(bcResult.getBalance_arrearInterest()).doubleValue());
        bcResult.setBalance_currentTax(formatAmt(bcResult.getBalance_currentTax()).doubleValue());
        bcResult.setBalance_currentInterest(formatAmt(bcResult.getBalance_currentInterest()).doubleValue());
        bcResult.setBalance_total(formatAmt(bcResult.getBalance_total()).doubleValue());
        bcResult.setBalance_totalInterest(formatAmt(bcResult.getBalance_totalInterest()).doubleValue());

        bcResult.setArrears_demand(formatAmt(bcResult.getArrears_demand()).doubleValue());
        bcResult.setArrears_demand_collection(formatAmt(bcResult.getArrears_demand_collection()).doubleValue());
        bcResult.setArrears_penalty(formatAmt(bcResult.getArrears_penalty()).doubleValue());
        bcResult.setArrears_penalty_collection(
                formatAmt(bcResult.getArrears_penalty_collection()).doubleValue());

        bcResult.setCurrent_demand(formatAmt(bcResult.getCurrent_demand()).doubleValue());
        bcResult.setCurrent_demand_collection(formatAmt(bcResult.getCurrent_demand_collection()).doubleValue());
        bcResult.setCurrent_penalty(formatAmt(bcResult.getCurrent_penalty()).doubleValue());
        bcResult.setCurrent_penalty_collection(
                formatAmt(bcResult.getCurrent_penalty_collection()).doubleValue());
        bcResult.setTarget_total_demand(formatAmt(bcResult.getTarget_total_demand()).doubleValue());
        bcResult.setCummulative_total_Collection(
                formatAmt(bcResult.getCummulative_total_Collection()).doubleValue());
        bcResult.setTarget_total_demandInterest(
                formatAmt(bcResult.getTarget_total_demandInterest()).doubleValue());
        bcResult.setCummulative_total_CollectionInterest(
                formatAmt(bcResult.getCummulative_total_CollectionInterest()).doubleValue());
        bcResult.setCummulative_total_CollectionPercentage(
                bcResult.getCummulative_total_CollectionPercentage().setScale(2, BigDecimal.ROUND_HALF_EVEN));
        bcResult.setCummulative_total_CollectionInterestPercentage(bcResult
                .getCummulative_total_CollectionInterestPercentage().setScale(2, BigDecimal.ROUND_HALF_EVEN));
    }

}

From source file:org.egov.adtax.service.AdvertisementDemandService.java

public Map<String, BigDecimal> checkPendingAmountByDemand(final AdvertisementPermitDetail advPermitDetail) {
    final Map<String, BigDecimal> demandFeeType = new LinkedHashMap<>();
    BigDecimal totalDemand = BigDecimal.ZERO;
    BigDecimal totalCollection = BigDecimal.ZERO;
    BigDecimal totalPending = BigDecimal.ZERO;
    BigDecimal penaltyAmount = BigDecimal.ZERO;
    BigDecimal additionalTaxAmount = BigDecimal.ZERO;
    if (advPermitDetail != null && advPermitDetail.getAdvertisement() != null
            && advPermitDetail.getAdvertisement().getDemandId() != null) {
        for (final EgDemandDetails demandDtl : advPermitDetail.getAdvertisement().getDemandId()
                .getEgDemandDetails()) {
            totalDemand = totalDemand.add(demandDtl.getAmount());
            totalCollection = totalCollection.add(demandDtl.getAmtCollected());
            totalPending = totalPending.add(demandDtl.getAmount().subtract(demandDtl.getAmtCollected()));
        }//w ww .  ja v a 2 s.  c  om
        penaltyAmount = advertisementPenaltyCalculator.calculatePenalty(advPermitDetail);
        additionalTaxAmount = advertisementAdditionalTaxCalculator
                .getTotalAdditionalTaxesByPassingAdvertisementPermit(advPermitDetail);

    }
    totalDemand = totalDemand.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    totalCollection = totalCollection.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    totalPending = totalPending.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    penaltyAmount = penaltyAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    demandFeeType.put(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT, totalPending);
    demandFeeType.put(AdvertisementTaxConstants.TOTAL_DEMAND, totalDemand);
    demandFeeType.put(AdvertisementTaxConstants.TOTALCOLLECTION, totalCollection);
    demandFeeType.put(AdvertisementTaxConstants.PENALTYAMOUNT, penaltyAmount);
    demandFeeType.put(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT,
            additionalTaxAmount.setScale(0, BigDecimal.ROUND_HALF_UP));
    return demandFeeType;
}

From source file:com.ardhi.businessgame.services.BusinessGameService.java

public String loadInstallmentDetails(HttpServletRequest req) {
    String val = "0";
    ArrayList<InstallmentEmployee> employees = new ArrayList<InstallmentEmployee>();
    ArrayList<InstallmentEquipment> equipments = new ArrayList<InstallmentEquipment>();
    ArrayList<String> data = new ArrayList<String>();

    SqlRowSet srs1 = db.getJdbc().queryForRowSet(
            "select installment_employee.id,employee,quality,operational,draw from installment_employee,list_employee,desc_employee,info_employee where installment='"
                    + req.getParameter("id")
                    + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id and name=employee"),
            srs2;//from w  ww  . j av a 2s.  co  m

    while (srs1.next()) {
        employees.add(new InstallmentEmployee(srs1.getString("id"), srs1.getString("employee"),
                srs1.getInt("quality"), srs1.getDouble("operational"), srs1.getString("draw")));
    }

    srs1 = db.getJdbc().queryForRowSet(
            "select installment_equipment.id,equipment,quality,durability,size,operational,draw from installment_equipment,desc_equipment,list_equipment,info_equipment where installment='"
                    + req.getParameter("id")
                    + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment");
    while (srs1.next()) {
        equipments.add(new InstallmentEquipment(srs1.getString("id"), srs1.getString("equipment"),
                srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"),
                srs1.getDouble("operational"), srs1.getString("draw")));
    }

    ArrayList<String> installmentIOdata = calculateInstallmentAndIOByIdInstallment(req.getParameter("id"));
    data.add(installmentIOdata.get(0));
    data.add(installmentIOdata.get(1));
    data.add(installmentIOdata.get(2));
    data.add(installmentIOdata.get(3));
    data.add(installmentIOdata.get(4));
    data.add(installmentIOdata.get(5));
    data.add(installmentIOdata.get(6));
    data.add(installmentIOdata.get(7));
    data.add(gson.toJson(equipments));
    data.add(gson.toJson(employees));

    if (installmentIOdata.get(0).equals("Petrol Power Plant")) {
        srs1 = db.getJdbc().queryForRowSet(
                "select subscription,tariff from installment where id='" + req.getParameter("id") + "'");
        double tariff, subscription;
        if (srs1.next()) {
            subscription = srs1.getDouble("subscription");
            tariff = srs1.getDouble("tariff");
        } else
            return "0";

        srs1 = db.getJdbc()
                .queryForRowSet("select id,type,[user],planned_supply from installment where supply='"
                        + req.getParameter("id") + "'");
        ArrayList<String> types = new ArrayList<String>(), users = new ArrayList<String>(),
                idSupplies = new ArrayList<String>();
        ArrayList<Double> supplies = new ArrayList<Double>();
        while (srs1.next()) {
            idSupplies.add(srs1.getString("id"));
            types.add(srs1.getString("type"));
            users.add(srs1.getString("user"));
            supplies.add(srs1.getDouble("planned_supply"));
        }

        data.add(gson.toJson(subscription));
        data.add(gson.toJson(tariff));
        data.add(gson.toJson(types));
        data.add(gson.toJson(users));
        data.add(gson.toJson(supplies));
        data.add(gson.toJson(idSupplies));

        val = gson.toJson(data);

        types = null;
        users = null;
        supplies = null;
        idSupplies = null;

    } else {
        srs1 = db.getJdbc().queryForRowSet(
                "select supply,planned_supply from installment where id='" + req.getParameter("id") + "'");
        ArrayList<String> idSupplies = new ArrayList<String>(), users = new ArrayList<String>(), tmpSupplies;
        ArrayList<Double> subscriptions = new ArrayList<Double>(), tariffs = new ArrayList<Double>(),
                availables = new ArrayList<Double>();
        JsonParser parser = new JsonParser();
        JsonArray array1;
        int tmp;
        double available, currentKwh;
        String currentSupply;

        if (srs1.next()) {
            currentKwh = srs1.getDouble("planned_supply");
            currentSupply = srs1.getString("supply");
        } else
            return "0";

        srs1 = db.getJdbc().queryForRowSet(
                "select id,[user],subscription,tariff from installment where type='Petrol Power Plant'");
        while (srs1.next()) {
            tmp = 0;
            tmpSupplies = calculateInstallmentAndIOByIdInstallment(srs1.getString("id"));
            array1 = parser.parse(tmpSupplies.get(5)).getAsJsonArray();
            for (int i = 0; i < array1.size(); i++) {
                if ((new Gson().fromJson(array1.get(i), String.class)).equals("Energy")) {
                    tmp = i;
                    break;
                }
            }
            array1 = parser.parse(tmpSupplies.get(6)).getAsJsonArray();
            available = new Gson().fromJson(array1.get(tmp), Double.class);
            srs2 = db.getJdbc().queryForRowSet(
                    "select planned_supply from installment where supply='" + srs1.getString("id") + "'");
            while (srs2.next())
                available -= srs2.getDouble("planned_supply");

            idSupplies.add(srs1.getString("id"));
            users.add(srs1.getString("user"));
            subscriptions.add(srs1.getDouble("subscription"));
            tariffs.add(srs1.getDouble("tariff"));
            availables.add(new BigDecimal(Double.valueOf(available)).setScale(2, BigDecimal.ROUND_HALF_EVEN)
                    .doubleValue());
            tmpSupplies = null;
        }

        data.add(gson.toJson(idSupplies));
        data.add(gson.toJson(users));
        data.add(gson.toJson(subscriptions));
        data.add(gson.toJson(tariffs));
        data.add(gson.toJson(availables));
        data.add(gson.toJson(currentKwh));
        data.add(gson.toJson(currentSupply));

        val = gson.toJson(data);

        idSupplies = null;
        users = null;
        tariffs = null;
        availables = null;
        currentSupply = null;
    }

    installmentIOdata = null;
    employees = null;
    equipments = null;
    data = null;
    srs1 = null;
    srs2 = null;

    gc();

    return val;
}

From source file:org.lockss.util.NumberUtil.java

/**
 * Round to given number of digits after decimal point
 * //from www .j a v a2  s.  com
 * @param d
 * @param decimalPlace
 * @return argument rounded to 
 */
public static double roundToNDecimals(double d, int decimalPlaces) {
    BigDecimal bd = new BigDecimal(d);
    bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_EVEN);
    return bd.doubleValue();
}

From source file:org.egov.egf.web.actions.payment.DirectBankPaymentAction.java

public String getComments() {
    return getText("payment.comments", new String[] {
            paymentheader.getPaymentAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString() });
}