金额计算:

 

   public static void main(String[] args) {

    double num =  562134;

   String percent = "80%";

   double d = getResult(num, percent);

   System.out.println(num + " * " + percent + " = " + d);

   }

 

   public static double getResult(double num, String percent){

   double result = 0;

   String percentNumStr = percent.substring(0, percent.length() - 1);

   System.out.println("percentNum = " + percentNumStr);

   double percentNum = Double.valueOf(percentNumStr)/100;

   System.out.println("percentNum = " + percentNum);

   BigDecimal d1=new BigDecimal(Double.toString(num));

BigDecimal d2=new BigDecimal(Double.toString(percentNum));

   //result = num * percentNum;

   result =d1.multiply(d2).doubleValue();

   System.out.println("result  = " + result );

   return result;

}