Sunshine
2024-11-04 7f1a0e49c1fe0c3f9f8a2493f30451d90b62ab64
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.nova.sankuai.infra.utils;
 
import java.math.BigDecimal;
import java.text.DecimalFormat;
 
/**
 * @author ephemeral
 * @date 2022/7/9 13:26
 */
public class MoneyUtil {
 
    private MoneyUtil(){
    }
 
    /**
     * 分转元
     *
     * @param num
     * @return String
     * @Title: formatPrice
     * @Description:分转元
     * @throw
     */
    public static String toYuan(Integer num) {
        if (num == null) {
            return "0.00";
        }
        DecimalFormat df = new DecimalFormat("0.00");
        BigDecimal bigDecimal = new BigDecimal(num).divide(new BigDecimal(100));
        String str = df.format(bigDecimal);
        return str;
    }
 
    /**
     * 分转元
     *
     * @param num
     * @return String
     * @Title: formatPrice
     * @Description:分转元
     * @throw
     */
    public static String toYuan(Long num) {
        if (num == null) {
            return "0.00";
        }
        DecimalFormat df = new DecimalFormat("0.00");
        BigDecimal bigDecimal = new BigDecimal(num).divide(new BigDecimal(100));
        String str = df.format(bigDecimal);
        return str;
    }
 
    /**
     * 元转分
     *
     * @param num
     * @return int
     * @Title: formatPrice
     * @Description: 元转分
     * @throw
     */
    public static int toFen(String num) {
        if (num == null) {
            return 0;
        }
        DecimalFormat df = new DecimalFormat("#0");
        BigDecimal bigDecimal = new BigDecimal(num).multiply(new BigDecimal(100));
        String str = df.format(bigDecimal);
        return Integer.parseInt(str);
    }
 
    /**
     * 元转分
     *
     * @param num
     * @return int
     * @Title: formatPrice
     * @Description: 元转分
     * @throw
     */
    public static Long toFen4Long(String num) {
        if (num == null) {
            return 0L;
        }
        DecimalFormat df = new DecimalFormat("#0");
        BigDecimal bigDecimal = new BigDecimal(num).multiply(new BigDecimal(100));
        String str = df.format(bigDecimal);
        return Long.parseLong(str);
    }
}