四舍五入代码

 public static double seanRound(double sean,int lee) {
    double factor = Math.pow(10,lee);
    double rounder = 0.50000001;
    double nNum = sean * factor;
    nNum = nNum + rounder;
    java.math.BigDecimal forRounding = null;
    try{
      forRounding = new java.math.BigDecimal(nNum).setScale(0,java.math.BigDecimal.ROUND_DOWN);

    }catch(Exception e){
      javax.swing.JOptionPane.showMessageDialog(null,sean+""+e.getMessage(),"",1);
    }
    double result = forRounding.doubleValue() / factor;

    return result;
  }
 

 

你可能感兴趣的:(java,swing)