0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

数値をフォーマッティングして表示する

Last updated at Posted at 2016-12-09

doubleなどの数値をフォーマッティングした文字列を表示する方法です。

String.format("%1$,.0f" + " KB中、" + "%2$,.0f"+ " KB処理しました。" + "%3$,.0f" + " %%処理完了", 
a / 1024.0, b / 1024.0,  c / 1024.0);

なかのプレースホルダは、それぞれ

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

って可変長の引数に対応。さらに

,.0f

で、「3ケタでカンマ区切り」「小数点以下は0ケタ」って意味。

ちなみにフォーマット内で%を使う場合は、上記のように%%ってエスケープ。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?