DecimalFormat 数据格式化类的使用小结
import java.text.DecimalFormat;
import java.util.Random;
import java.util.Locale;
public class TestNumberFormat {
public static void main(String[] args) {
double pi = 3.1415927;
System.out.println(new DecimalFormat("0").format(pi));
System.out.println(new DecimalFormat("0.00").format(pi));
System.out.println(new DecimalFormat("00.000").format(pi));
System.out.println(new DecimalFormat("#").format(pi));
System.out.println(new DecimalFormat("#.##%").format(pi));
long c = 299792458;
System.out.println(new DecimalFormat("#.#####E0").format(c));
System.out.println(new DecimalFormat("00.####E0").format(c));
System.out.println(new DecimalFormat(",###").format(c));
System.out.println(new DecimalFormat("光速大小为每秒,###米。").format(c));
System.out.println(Math.floor(24.335*100)/100);
System.out.println((int)Math.floor(23.45));
System.out.println((int)Math.ceil(23.2));
System.out.println((int)Math.rint(23.567));
System.out.println(new DecimalFormat("0").format(25.5));
System.out.println(Math.random());
System.out.println(new Random().nextFloat());
System.out.println(new Random().nextBoolean());
}
}