Formatting Decimal Number
问题 I am formatting a decimal number and I have the following criteria to format it: Number should be at most two decimal places ( 10.1234=>10.12 ) If there is only one digit after decimal then it will ends up with an extra 0 ( 10.5=>10.50 ) Thousand separator will be comma ( 12345.2345 => 12,345.23 ) I have written following logic: double x = Double.parseDouble(value.toString()); String dec = x % 1 == 0 ? new java.text.DecimalFormat("###,###.##").format(x) : new java.text.DecimalFormat("###,###