將雙值格式化為2個十進制位置的最佳方法我正在處理我的應用程序中的很多雙值,有什么簡單的方法來處理Java中十進制值的格式化嗎?還有比這更好的方法嗎? DecimalFormat df = new DecimalFormat("#.##");基本上,我想做的是格式化雙值,如23.59004 to 23.5935.7 to 35.703.0 to 3.009 to 9.00
2 回答

交互式愛情
TA貢獻1712條經驗 獲得超3個贊
String.format
:
double[] arr = { 23.59004, 35.7, 3.0, 9};for ( double dub : arr ) { System.out.println( String.format( "%.2f", dub ) );}
23.5935.703.009.00
System.out.format
java.util.Formatter
添加回答
舉報
0/150
提交
取消