package org.arpit.java2blog;
public class StringFromatformatDouble {
public static void main(String[] args) {
double d = 2.456534;
System.out.println("Double upto 2 decimal places: "+String.format("%.2f",d));
}
}
String strDouble = String.format("%.2f", 1.23456);
DecimalFormat df = new DecimalFormat("#.##");
String formatted = df.format(2.456345);
System.out.println(formatted);
double input = 3.14159265359;
System.out.format("double : %.2f", input); // 3.14
System.out.println("double : " + String.format("%.2f", input)); // 3.14
DecimalFormat df = new DecimalFormat("#.00");
package org.arpit.java2blog;
public class PrintfformatDouble {
public static void main(String[] args) {
double d = 2.456534;
System.out.printf("Double upto 2 decimal places: %.2f",d);
}
}
int x = (int) y