Format and display numbers

This is a method to display a character string formatted with a numerical value such as double.

String.format("%1$,.0f" + "In KB," + "%2$,.0f"+ "KB processed." + "%3$,.0f" + " %%Processing completed", 
a / 1024.0, b / 1024.0,  c / 1024.0);

The placeholders inside are

%1$ -> a / 1024.0
%2$ -> b / 1024.0
%3$ -> c / 1024.0

Corresponds to variable length arguments. further

,.0f

So, it means "separated by commas with 3 digits" and "0 digits after the decimal point".

By the way, when using% in the format, escape by %% as above. ..

Recommended Posts

Format and display numbers
Calculate and display grades
[Java] How to get the current date and time and specify the display format
Visually understand Fibonacci numbers and recursive functions