Java:有没有什么方法能把数字转换成易读的形式,如10000自动转换成1w的形式?
2个回答
展开全部
public class main {
public static String trans(double num) {
String[] unit = new String[] { "万", "亿", "兆", "京", "垓", "秭", "穣", "沟", "涧", "正", "载", "极", "恒河沙", "阿僧祇", "那由他", "不可思议", "无量大数" };
for (String u : unit) {
if (num < 10000) {
return String.format("%.2f%s", num, u);
}
num /= 10000D;
}
return "无穷";
}
public static void main(String[] args) {
System.out.println(trans(1000000D));
System.out.println(trans(100003456542342342334523452345234523456456300D));
System.out.println(trans(10023420000D));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询