shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.walker.infrastructure.utils;
 
import java.text.DecimalFormat;
 
/**
 * 数值格式工具类。
 * @author 时克英
 * @date 2022-09-26
 */
public class NumberFormatUtils {
 
//    private static final DecimalFormat df2 = new DecimalFormat("#.00");
//    private static final DecimalFormat df2 = new DecimalFormat("#.##");
 
    /**
     * 把精度小数,按四舍五入方式,转成整数。
     * @param value
     * @return
     * @date 2023-07-08
     */
    public static final double scaleRoundToInt(double value){
        if(value <= 0){
            return value;
        }
        return new Double(Math.round(value)).intValue();
    }
 
    /**
     * 给定数值保留2位小数。
     * @param value
     * @return
     */
    public static final double scaleAccuracy2(double value){
        DecimalFormat df2 = new DecimalFormat("#.00");
        String score = df2.format(value);
        return Double.parseDouble(score);
    }
}