Formatting Output
Why when I type this code report += "Total Value: $%.2f" + (value) + "\n";does it not give 2 digits? and instead returns thisTotal Value: 11.059999999999999Thanks!
public class FormatExample {
public static void main(String[] args) {
String s = String.format("Total Value: $%.2f%n", Math.PI);
System.out.println(s);
}
}
> System.out.printf("Total Value: $%.2f%n", Math.PI);We prefer System.out.format("Total Value: $%.2f%n", Math.PI),but used String.format because in the original code, the OP didn'tprint the string to System.out