我想使用大数值格式化程序设置自定义后缀。它的默认后缀是:
但我想将其自定义为:
我曾尝试将其默认值更改为rb,jt,m和t,但结果仅为:
并且没有m和t的概率,因为它仅包含1个后缀
private String[] mSuffix = new String[]{"", "k", "m", "b", "t"};
结果是: 812k, 8.12m, 8.12b, 8.12吨
试图将其更改为:
private String[] mSuffix = new String[]{"", "rb", "jt", "m", "t"};
结果是: 812r, 8.12j, 8.12m, 8.12吨
这是使用mSuffix的时候
private String makePretty(double number) {
String r = mFormat.format(number);
int numericValue1 = Character.getNumericValue(r.charAt(r.length() - 1));
int numericValue2 = Character.getNumericValue(r.charAt(r.length() - 2));
int combined = Integer.valueOf(numericValue2 + "" + numericValue1);
r = r.replaceAll("E[0-9][0-9]", mSuffix[combined / 3]);
while (r.length() > mMaxLength || r.matches("[0-9]+\\.[a-z]")) {
r = r.substring(0, r.length() - 2) + r.substring(r.length() - 1);
}
return r;
}
我希望输出是
预先感谢
答案 0 :(得分:3)
假设mFormat.formatter(number);
做正确的事情(5000.0->“ 5k”),则:
private String makePretty(double number) {
String r = mFormat.format(number);
if (r.indexOf("k") > 0) {
r = r.replace("k", "rb");
} else if (r.indexOf("m") > 0) {
r = r.replace("m", "jt");
} else if (r.indexOf("b") > 0) {
r = r.replace("b", "m")
}
return r;
}