xuekang
2024-05-11 bac0878349a1db23e7b420ea164e22fb9db73a99
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
91
92
93
94
95
96
97
98
99
100
101
package com.nuvole.poscom.util;
 
import java.math.BigDecimal;
 
/**
 * @Description 语音内容格式化
 * @Author ZHAOXL
 * @Date 2024/3/7 13:15
 * @Version 1.0
 */
public class PoscomVoice {
 
    /**
     * 支付宝
     */
    public final static String ZFB = "2007";
    /**
     * 微信
     */
    public final static String WX = "2008";
 
    /**
     * 云闪付
     */
    public final static String YSF = "2011";
 
    /**
     * 现金
     */
    public final static String XJ = "2014";
 
    /**
     * 语音类型。
     * 2 不自动播放新订单,真人语音
     */
    public final static String VOICE_TYPE_2 = "2";
 
    /**
     * 语音中部内容
     */
    public final static String VOICE_MIDDLE = "已收款";
 
    /**
     * 分隔符
     */
    public final static String SPLIT = "|";
 
    private final static String unit[][] = {{"", "万", "亿"}, {"", "十", "百", "千"}};
 
    /**
     * 格式化语音字符串
     * @param strs 参数
     * @return String
     * @Author ZHAOXL
     * @Date 2024/3/7 13:57
     * @Version 1.0
     */
    public static String format(String strs) {
        StringBuilder sb=new StringBuilder();
        for (char c : strs.toCharArray()) {
            sb.append(c);
            sb.append(SPLIT);
        }
        return sb.toString();
    }
 
    /**
     * 格式化金额
     * @param price 金额
     * @return String
     * @Author ZHAOXL
     * @Date 2024/3/7 16:07
     * @Version 1.0
     */
    public static String priceFormat(Long price) {
        BigDecimal decimal = new BigDecimal("" + price).divide(new BigDecimal("100"));
        Double n = decimal.doubleValue();
        StringBuilder sb = new StringBuilder();
        String numStr = String.valueOf(n);
        int dotIndex = numStr.indexOf(".");
        String decimalPart = numStr.substring(dotIndex);
        if (".0".equals(decimalPart)) {
            decimalPart = "";
        }
        int integerPart = (int) Math.floor(n);
        if (integerPart == 0) {
            sb.append("0");
        };
        for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
            sb.insert(0, unit[0][i]);
            for (int j = 0; j < unit[1].length && n > 0; j++) {
                if (integerPart % 10 > 0) {
                    sb.insert(0, integerPart % 10 + unit[1][j]);
                }
                integerPart = integerPart / 10;
            }
        }
        sb.append(decimalPart + "元");
        return sb.toString();
    }
}