提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
具有自定义格式###,###。##的格式编号
import java.text.DecimalFormat; /* from 时 代 J a v a 公 众 号*/ public class FPAdder { public static void main(String[] args) { int numArgs = args.length; //this program requires at least two arguments on the command line if (numArgs < 2) { System.out .println("This program requires two command-line arguments."); } else { double sum = 0.0; for (int i = 0; i < numArgs; i++) { sum += Double.valueOf(args[i]).doubleValue();/*N o w J a v a . c o m - 时代Java 提 供*/ } //format the sum DecimalFormat myFormatter = new DecimalFormat("###,###.##"); String output = myFormatter.format(sum); //print the sum System.out.println(output); } } }