Question : printing out double to 2 decimal places

I am making a simple prgram in NetBeans that asks for order amount and then outputs order amount plus shipping charge if order is under $25. The proble is that the output is not in a dollar format or 2 decimal places. It outputs one decimal place, or if the user inputs 28.6795 then the pogram outputs that number. I am a true beginner at this, as in only a couple of days, and I cannot seem to get a complete answer.

Answer : printing out double to 2 decimal places

Use java.text.DecimalFormat to do the work for you:


1:
2:
3:
4:
5:
 	public static void main(String[] args) {
		java.text.DecimalFormat format = new java.text.DecimalFormat("#,##0.00");
		System.out.println( format.format(10000000.67890)); 
		// output is "10.000.000,68"
	}
Random Solutions  
 
programming4us programming4us