1 package com.test.math;
2
3 import java.math.BigDecimal;
4 import java.math.RoundingMode;
5
6 public class sss {
7 public static void main(String[] args) {
8 //声明任意小数,正负均可
9 double num=-3.232527824534
;
10 //保留小数后几位
11 int digit=4
;
12 BigDecimal bd =
new BigDecimal(num);
13 double result =
bd.setScale(digit,RoundingMode.HALF_UP).doubleValue();
14 System.out.println(result);
15 }
16 }
转载于:https://www.cnblogs.com/bilaisheng/p/4976155.html
转载请注明原文地址: https://mac.8miu.com/read-1554.html