【发布时间】:2017-03-20 02:54:30
【问题描述】:
对不起,我是新手,如何在旧 API 中调用它? 获取此警告调用需要 api 级别 24(当前最低为 21)新的 android.icu.text.DecimalFormat
public static String roundThousandsIntoK(Number number) {
char[] suffix = {' ', 'k', 'M', 'B', 'T', 'P', 'E'};
long numValue = number.longValue();
int value = (int) Math.floor(Math.log10(numValue));
int base = value / 3;
if (value >= 3 && base < suffix.length) {
return new DecimalFormat("#0.0").format(numValue / Math.pow(10, base * 3)) + suffix[base];
} else {
return new DecimalFormat("#,##0").format(numValue);
}
}
【问题讨论】:
-
您可能想要
java.text.DecimalFormat而不是android.icu.text.DecimalFormat。检查文件顶部的import语句。 -
哇,太快了,非常感谢