package com.newvideo.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();
|
}
|
|
}
|