admin
2022-01-28 cd7767932dddeaf6d9c73a83d4a9b38f0341b77f
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
package com.yeshi.buwan.util;
 
import java.text.DecimalFormat;
import java.util.regex.Pattern;
 
import javax.persistence.Entity;
 
@Entity
public class NumberUtil {
 
    public static String get2PointNumber(float price) {
        DecimalFormat decimalFormat = new DecimalFormat(".00");// 构造方法的字符格式这里如果小数不足2位,会以0补足.
        String p = decimalFormat.format(price);// format 返回的是字符串
        return p;
    }
 
    public static String get1PointNumber(float price) {
        DecimalFormat decimalFormat = new DecimalFormat(".0");// 构造方法的字符格式这里如果小数不足2位,会以0补足.
        String p = decimalFormat.format(price);// format 返回的是字符串
        return p;
    }
 
    public static String get1PointNumber(double price) {
        DecimalFormat decimalFormat = new DecimalFormat(".0");// 构造方法的字符格式这里如果小数不足2位,会以0补足.
        String p = decimalFormat.format(price);// format 返回的是字符串
        return p;
    }
 
    public static String get1Point(float d) {
        DecimalFormat fnum = new DecimalFormat("##0.0");
        String dd = fnum.format(d);
        return dd;
    }
 
    public static String get1Point(String d) {
        try {
            return get1Point(Float.parseFloat(d));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "9.0";
    }
 
    private static String getNumberWithZero(int number) {
        if (number < 10)
            return "0" + number;
        else
            return number + "";
    }
 
    // 将秒转化为标准时间长度
    public static String convertSecondToString(int second) {
        if (second < 60) {// 小于1分钟
            return "00:" + getNumberWithZero(second);
        } else if (second < 60 * 60) {// 小于1小时
            int minite = second / 60;
            return getNumberWithZero(minite) + ":"
                    + getNumberWithZero(second % 60);
        } else {
            int hour = second / (60 * 60);
            int minite = (second % (60 * 60)) / 60;
            int se = (second % (60 * 60)) % 60;
            return getNumberWithZero(hour) + ":" + getNumberWithZero(minite)
                    + ":" + getNumberWithZero(se);
        }
    }
 
    public static boolean isNumeric(String str) {
 
        if (str == null || "".equals(str.trim())) {
            return false;
        }
 
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }
 
}