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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Use the DecimalFormat class, see the link for how to use.
To save you searching I have written what you basically need
You can try like this:
This will display the numbers in the format
EDIT:-
I know its a late edit but yes there is one more way:
Call this function and you will get the output as follows:
how about below approach, but it's supported in Java 7 and later versions:
You will probably just want to use a string for this. If you need to do some calculations simply keep it as an int until it needs to be printed. Then when it needs to be printed convert it to a string, process the string so that its as readable as you would like, and print it.
You can also try DecimalFormat;
Results:
You can use decimal format to format the string
This will print 100,000,000
For other input - say 1000 it would print 1,000