length « decimal « Java Data Type Q&A





1. fixed length decimal numbers    coderanch.com

>> I want to get 3.14 not 3.14285 In fact you really don't know what the value is until you observe it. So it makes sense to display it in the form you want while preserving the maximum precision the rest of the time. double value = 3.143423432432; System.out.printf("%.2f", value); // Prints: 3.14