zhanghua
2023-11-02 46251c20b66bb1ca05058ae63a92a195e5543b90
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
package com.ycl.utils;
 
import java.math.BigDecimal;
import java.text.DecimalFormat;
 
public class StringUtils {
 
    /**
     * 不处理大小写
     * helloWorld=>hello_World
     * HelloWorld=>Hello_World
     *
     * @param content
     * @return
     */
    private static String camelToUnderlineIgnoreCase(String content) {
        return new StringBuilder(16)
                .append(content.substring(0, 1))
                .append(content.substring(1).replaceAll("([A-Z])", "_$1"))
                .toString();
    }
 
 
    /**
     * 驼峰转全小下划线
     * helloWorld=>hello_world
     * HelloWorld=>hello_world
     *
     * @return
     */
    public static String camelToUnderlineLowerCase(String content) {
        return camelToUnderlineIgnoreCase(content).toLowerCase();
    }
 
 
    /**
     * 驼峰转全大写下划线
     * helloWorld=>HELLO_WORLD
     * HelloWorld=>HELLO_WORLD
     *
     * @return
     */
    public static String camelToUnderlineUpperCase(String content) {
        return camelToUnderlineIgnoreCase(content)
                .toLowerCase();
    }
 
 
    /**
     * 下划线转小驼峰
     * hello_world=>helloWorld
     * HELLO_WORLD=>helloWorld
     * Hello_World=>helloWorld
     *
     * @param content
     * @return
     */
    public static String underlineToLowerCamelCase(String content) {
        return new StringBuilder(16)
                .append(content.substring(0, 1).toLowerCase())
                .append(content.substring(1).replaceAll("_([a-zA-Z])", "$1".toUpperCase()))
                .toString();
    }
 
 
    /**
     * 下划线转大驼峰
     * hello_world=>HelloWorld
     * HELLO_WORLD=>HelloWorld
     * Hello_World=>HelloWorld
     *
     * @param content
     * @return
     */
    public static String underlineToCamelUpperCase(String content) {
        return new StringBuilder(16)
                .append(content.substring(0, 1).toUpperCase())
                .append(content.substring(1).replaceAll("_([a-zA-Z])", "$1".toUpperCase()))
                .toString();
    }
 
    public static String doubleTwo(Double value) {
        return String.format("%.2f", value);
    }
}