[ジャワ] Javaでいくつかの形式で – Javaでの数値の印刷出力のフォーマット
ジャワの提供 2 我々はフォーマットの方法 printfの と フォーマット と 2 この方法は、同様の機能を有する.
とともに 1 変数は、さまざまな方法、それを持つでフォーマットすることができます. 最高経営責任者(CEO
System.out.format("The value of " + "the float variable is " +
"%f, while the value of the " + "integer variable is %d, " +
"and the string is %s", floatVar, intVar, stringVar);
int i = 461012;
System.out.format("The value of i is: %d%n", i);
もう一つは、あなたがフランスのシステムに応じたフォーマットを印刷できるということです, 整数部と小数形式の実数の小数部を分離 Locale.FRANCE. 最高経営責任者(CEO:
System.out.format(Locale.FRANCE,
"The value of the float " + "variable is %f, while the " +
"value of the integer variable " + "is %d, and the string is %s%n",
floatVar, intVar, stringVar);
私は、テーブル形式を持っている:

そして、あなたは簡単なプログラムを実行することができます:
import java.util.Calendar;
import java.util.Locale;
public class FormattingNumericPrintOutput {
public static void main(String[] args) {
long n = 461012;
System.out.format("%d%n", n); // --> "461012"
System.out.format("%08d%n", n); // --> "00461012"
System.out.format("%+8d%n", n); // --> " +461012"
System.out.format("%,8d%n", n); // --> " 461,012"
System.out.format("%+,8d%n%n", n); // --> "+461,012"
double pi = Math.PI;
System.out.format("%f%n", pi); // --> "3.141593"
System.out.format("%.3f%n", pi); // --> "3.142"
System.out.format("%10.3f%n", pi); // --> " 3.142"
System.out.format("%-10.3f%n", pi); // --> "3.142"
System.out.format(Locale.FRANCE, "%-10.4f%n%n", pi); // --> "3,1416" //in theo hệ thống Pháp
Calendar c = Calendar.getInstance(); //lấy thời gian hiện hành
System.out.format("%tB %te, %tY%n ", c, c, c); // --> "July 20, 2013"
System.out.format("%tl:%tM %tp%n", c, c, c); // --> " 2:51 pm"
System.out.format("%tD%n", c); // --> "07/20/13"
}
}



彼àフロートに応じて二重データ型の形式の場合?