1.PK值格式化样式修改

2.按人数PK公屏增加胜利方战斗值展示
This commit is contained in:
huangjian
2020-12-22 11:26:13 +08:00
parent 2234726c19
commit 61fbc15809
8 changed files with 77 additions and 55 deletions

View File

@@ -34,29 +34,33 @@ public class FormatUtils {
/**
* 把过长的金额类数字,转换成两位小数带万,亿,兆 缩写
* 10000.00 -> 1.00万 丢掉两位小数后面的小数
*
* @param num
* @return
*/
public static String formatToShortDown(double num){
public static String formatToShortDown(double num) {
return formatToShort(num, RoundingMode.DOWN);
}
/**
* 把过长的金额类数字,转换成两位小数带万,亿,兆 缩写
* 10000.00 -> 1.00万 四舍五入两位小数后面的小数
*
* @param num
* @return
*/
public static String formatToShortHalfUp(double num){
public static String formatToShortHalfUp(double num) {
return formatToShort(num, RoundingMode.HALF_UP);
}
/**
* 把过长的金额类数字,转换成两位小数带万,亿,兆 缩写
* 10000.00 -> 1.00万
*
* @param num
* @return
*/
public static String formatToShort(double num, RoundingMode roundingMode){
public static String formatToShort(double num, RoundingMode roundingMode) {
try {
DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
decimalFormat.setRoundingMode(roundingMode);
@@ -64,16 +68,16 @@ public class FormatUtils {
double yi = Math.pow(10.0f, 8);
double zhao = Math.pow(10.0f, 12);
double res = num;
if (Math.abs(num / wan) < 1){
if (Math.abs(num / wan) < 1) {
res = num;
return decimalFormat.format(res);
}else if(Math.abs(num / wan) >= 1 && Math.abs(num / yi) < 1){
} else if (Math.abs(num / wan) >= 1 && Math.abs(num / yi) < 1) {
res = num / wan;
return decimalFormat.format(res) + "";
}else if(Math.abs(num / yi) >= 1 && Math.abs(num /zhao) < 1){
} else if (Math.abs(num / yi) >= 1 && Math.abs(num / zhao) < 1) {
res = num / yi;
return decimalFormat.format(res) + "亿";
}else {
} else {
res = num / zhao;
return decimalFormat.format(res) + "";
}
@@ -85,21 +89,28 @@ public class FormatUtils {
/**
* 将手机号码 显示成带隐私形式
*
* @param phoneNum
* @param beginIndex 开始用* 号替换位置
* @param endIndex 结束用* 号替换位置
* @param endIndex 结束用* 号替换位置
* @return
*/
public static String formatPhoneNumWithPrivacy(String phoneNum, int beginIndex, int endIndex){
public static String formatPhoneNumWithPrivacy(String phoneNum, int beginIndex, int endIndex) {
StringBuffer resSB = new StringBuffer();
for (int i = 0; i < phoneNum.length(); i++) {
if (i >= beginIndex && i < endIndex){
if (i >= beginIndex && i < endIndex) {
resSB.append("*");
}else {
} else {
resSB.append(phoneNum.charAt(i));
}
}
return resSB.toString();
}
//PK值相关格式化方式,统一方法,方便以后更改样式
public static String formatPKValue(long value) {
if (value >= 100000) return (value / 100) / 100f + "";
return String.valueOf(value);
}
}