String.format and DecimalFormat

Run Settings
LanguageJava
Language Version
Run Command
import java.text.DecimalFormat; class Main { public static void main(String[] args) { final DecimalFormat decimalFormatter = new DecimalFormat("0.00"); double price = 25.0; double discount = price * 0.1; // 2.5 double finalPrice = price - discount; // 22.5 System.out.println("Discount: " + decimalFormatter.format(discount)); System.out.print(String.format("Final Price: %.2f%n", finalPrice)); } }
Editor Settings
Theme
Key bindings
Full width
Lines