`
pangxin12345
  • 浏览: 186195 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

四舍五入代码

    博客分类:
  • java
阅读更多
 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;
  }
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics