如何在int中添加空白空间? [英] How to add empty space inside int?

查看:148
本文介绍了如何在int中添加空白空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想要打印数字100000000.乍一看很难说这个数字代表了多少百万。是一千万还是一亿?如何让Java中的大数字看起来更具可读性?像这样的事情会很好: 100 000 000 。你可以马上知道这个数字是1亿。

解决方案

您也可以尝试DecimalFormat;

  DecimalFormat formatter = new DecimalFormat(#,###); 
System.out.println(formatter.format(100000));

结果:

  1000>> 1,000 
10000>> 10,000
100000>> 100,000
1000000>> 1,000,000
pre>

Let's say I want to print the number 100000000. At first sight it is difficult to tell how many millions this number is representing. Is it 10 million or 100 million? How can I make big numbers in Java look more readable? Something like this for instance would be great: 100 000 000. You can tell right away that the number is 100 million.

解决方案

You can also try DecimalFormat;

DecimalFormat formatter = new DecimalFormat("#,###");
System.out.println(formatter.format(100000));

Results:

1000>>1,000
10000>>10,000
100000>>100,000
1000000>>1,000,000

这篇关于如何在int中添加空白空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆