标签:static 一个 test val ext 个数 oid pre main
/**
* 将一个数字处理为以万为单位的字符串,保留两位小数
*
* @param num
* @return
*/
public static String getTenThousandOfANumber(Integer num) {
if (num < 10000) {
return String.valueOf(num);
}
String numStr = new DecimalFormat("#.00").format(num / 10000d);
String[] ss = numStr.split("\\.");
if ("00".equals(ss[1])) {
return ss[0] + "万";
} else if (‘0‘ == (ss[1].charAt(1))) {
return ss[0] + "." + ss[1].charAt(0) + "万";
} else {
return numStr + "万";
}
}
import java.text.DecimalFormat;
/**
* @author Yawei Xi
* @since 2018-7-31 11:40
*/
public class Test {
public static void main(String[] args) {
int a = 9999;
int b = 10000;
int c = 10001;
int d = 11000;
int e = 11100;
int f = 100000;
System.out.println(getTenThousandOfANumber(a));
System.out.println(getTenThousandOfANumber(b));
System.out.println(getTenThousandOfANumber(c));
System.out.println(getTenThousandOfANumber(d));
System.out.println(getTenThousandOfANumber(e));
System.out.println(getTenThousandOfANumber(f));
}
/**
* 将一个数字处理为以万为单位的字符串,保留两位小数
*
* @param num
* @return
*/
public static String getTenThousandOfANumber(Integer num) {
if (num < 10000) {
return String.valueOf(num);
}
String numStr = new DecimalFormat("#.00").format(num / 10000d);
String[] ss = numStr.split("\\.");
if ("00".equals(ss[1])) {
return ss[0] + "万";
} else if (‘0‘ == (ss[1].charAt(1))) {
return ss[0] + "." + ss[1].charAt(0) + "万";
} else {
return numStr + "万";
}
}
}
9999
1万
1万
1.1万
1.11万
10万
标签:static 一个 test val ext 个数 oid pre main
原文地址:https://www.cnblogs.com/freelancy/p/9395080.html