[Modify]修改夺宝数量超过10W显示为W字
This commit is contained in:
@@ -2,6 +2,7 @@ package com.yizhuan.xchat_android_library.utils;
|
||||
|
||||
import com.yizhuan.xchat_android_library.R;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@@ -114,4 +115,55 @@ public class FormatUtils {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
|
||||
public static String formatBigNum(String num) {
|
||||
if (StringUtils.isEmpty(num)) {
|
||||
// 数据为空直接返回0
|
||||
return "0";
|
||||
}
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!StringUtils.isNumeric(num)) {
|
||||
// 如果数据不是数字则直接返回0
|
||||
return "0";
|
||||
}
|
||||
|
||||
|
||||
BigDecimal b0 = new BigDecimal("100000");
|
||||
BigDecimal b1 = new BigDecimal("10000");
|
||||
BigDecimal b3 = new BigDecimal(num);
|
||||
|
||||
String formatedNum = "";//输出结果
|
||||
String unit = "";//单位
|
||||
|
||||
if (b3.compareTo(b0) < 0) {
|
||||
sb.append(b3);
|
||||
} else if (b3.compareTo(b0) == 0 || b3.compareTo(b0) > 0) {
|
||||
formatedNum = b3.divide(b1).toString();
|
||||
unit = "W";
|
||||
}
|
||||
if (!"".equals(formatedNum)) {
|
||||
int i = formatedNum.indexOf(".");
|
||||
if (i == -1) {
|
||||
sb.append(formatedNum).append(unit);
|
||||
} else {
|
||||
i = i + 1;
|
||||
String v = formatedNum.substring(i, i + 1);
|
||||
if (!v.equals("0")) {
|
||||
sb.append(formatedNum.substring(0, i + 1)).append(unit);
|
||||
} else {
|
||||
sb.append(formatedNum.substring(0, i - 1)).append(unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sb.length() == 0)
|
||||
return "0";
|
||||
return sb.toString();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user