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
1String strDouble = String.format("%.2f", 1.23456);
2
3DecimalFormat df = new DecimalFormat("#.##");
4String formatted = df.format(2.456345);
5System.out.println(formatted);
1NumberFormat formatter = new DecimalFormat("#0.00");
2System.out.println(formatter.format(4.0));