1
2package org.arpit.java2blog;
3
4public class StringFromatformatDouble {
5
6 public static void main(String[] args) {
7 double d = 2.456534;
8 System.out.println("Double upto 2 decimal places: "+String.format("%.2f",d));
9 }
10}
11
12
1DecimalFormat df = new DecimalFormat();
2df.setMaximumFractionDigits(2);
3System.out.println(df.format(decimalNumber));
1double input = 3.14159265359;
2System.out.format("double : %.2f", input); // 3.14
3System.out.println("double : " + String.format("%.2f", input)); // 3.14