Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8270135

BigDemo mutiply and divide BigDecimal returns a wrror result

    XMLWordPrintable

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
       question code
      Long sellerSettleMoney = new BigDecimal(param.getBaseMoney())
                      .multiply(new BigDecimal(sellerPercent))
                      .divide(percentDecimal, 0, BigDecimal.ROUND_HALF_UP).longValue();

      SettleParam param = new SettleParam();
                  param.setBaseMoney(12800L);
                  param.setTemplateId("N_1");
                  Map<IdentityEnum, String> paramsMap = new HashMap<IdentityEnum, String>(16);
                  paramsMap.put(IdentityEnum.PLATFORM, "50");
                  paramsMap.put(IdentityEnum.SELLER, "50");

          public static void main(String[] args) throws Exception {
              SettleParam param = new SettleParam();
              param.setBaseMoney(1800L);
              param.setTemplateId("N_1");
              Map<IdentityEnum, String> paramsMap = new HashMap<IdentityEnum, String>(16);
              paramsMap.put(IdentityEnum.PLATFORM, "50");
              paramsMap.put(IdentityEnum.SELLER, "50");
              param.setParamsMap(paramsMap);
              SettleCalculateResult result = SettleCalculate.calculate(param);
              System.out.println(result.getSettleResultMap().get(IdentityEnum.PLATFORM).getExpression());
              System.out.println(result.getSettleResultMap().get(IdentityEnum.PLATFORM).getSettleMoney());
              System.out.println(result.getSettleResultMap().get(IdentityEnum.SELLER).getExpression());
              Long sellerMoney = result.getSettleResultMap().get(IdentityEnum.SELLER).getSettleMoney();
              System.out.println(sellerMoney);
          }

      result: sellerMoney = 901 The correct result should be 900
      why?What are the possibilities?


      FREQUENCY : rarely


        Attachments

          Activity

            People

            Assignee:
            tongwan Andrew Wang
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: