對於double型或者float型數據, 有時候需要對其進行精確小數點後幾位:
double result = 564.1464515163514;
// 創建一個數值格式化對象
NumberFormat nf = NumberFormat.getInstance();
// 設置精確到小數點後2位
nf.setMaximumFractionDigits(2);
String str = nf.format(result);
結果: 564.15