我是靠谱客的博主 光亮西装,这篇文章主要介绍使用BigDecimal完成小数点后的精确位数的四舍五入,现在分享给大家,希望可以做个参考。

package com.ryan;

import java.math.BigDecimal;

class MyMath {
	public static double round(double num ,int scale) {
		BigDecimal big  = new BigDecimal(num);
		BigDecimal result = big.divide(new BigDecimal(1), scale, BigDecimal.ROUND_HALF_UP);
		return result.doubleValue();
	}
}

public class Test {
	public static void main(String[] args) {
		System.out.println("带小数的四舍五入测试" + MyMath.round(99.4567, 3)); //994.457
	}
}

最后

以上就是光亮西装最近收集整理的关于使用BigDecimal完成小数点后的精确位数的四舍五入的全部内容,更多相关使用BigDecimal完成小数点后内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部