将数据四舍五入到十位


 
 
/**
* 使用这个方法将订单金额在十位四舍五入
* 若:1568.145 装换后:1570
* 1522 转成 1520
*/
import java.math.BigDecimal;

public class myround {
    public static void main(String[] args) {
        myround  m = new myround();
        BigDecimal num = new BigDecimal(1245656.24);
        Double db = num.doubleValue();
        System.out.println(m.roundTen(db));
    }
    private int roundTen(double db) {
        int roundedInt = (int) Math.round(db);

        if (roundedInt % 10 < 5) {
        return (roundedInt / 10) * 10;
        }

        return (roundedInt / 10) * 10 + 10;

        }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM