JAvaのMathクラス
2222 ワード
1.Mathクラス:基本的な数学演算の方法を含むツールクラス(ツールクラス、一連の機能を完了できるクラスを表し、それらを使用する場合、ペアを作成する必要はありません)、Mathクラスを通じて直接呼び出します.
注意:予約ビット数DecimalFormatを表示します.
オブジェクトを作成し、format()を呼び出し、処理する数値にパラメータを入力します.
1 //
2 System.out.println(Math.abs(-6.6));
3 //
4 System.out.println(Math.ceil(12.1));
5 //
6 System.out.println(Math.floor(12.1));
7 //
8 System.out.println(Math.max(1, 1));
9 //
10 System.out.println(Math.min(1, 3));
11 //
12 System.out.println(Math.pow(2, 2));
13 //
14 System.out.println(Math.random());
//
System.out.println(Math.round(1.6));
注意:予約ビット数DecimalFormatを表示します.
オブジェクトを作成し、format()を呼び出し、処理する数値にパラメータを入力します.
1 DecimalFormat df = new DecimalFormat("0.00");
2 System.out.println(df.format(Math.random()));