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
1num = 1.234
2print("{:.2f}".format(num))
3>> 1.23
4
5print(f"{num:.2f}")
6>> 1.23