This exercise is to print a decimal calculation with 2 decimal places
Exercise: Print the sales tax for purchase amount of 197.55 @ 6% interest with 2 decimal places.
Sales tax for purchase amount of 197.55 @ 6% is 11.85
Download Code: Salex Tax
Variations are possible. I personally used a slighty different code here:import java.text.DecimalFormat;public class Exercise6 { public static void main(String[] args){ double total = 197.55; double tax; double interest = 0.06; double int_perc = interest*100; tax = total * interest; DecimalFormat df = new DecimalFormat("#.##"); System.out.println("Sales tax for purchase amount of " +total+ " @ "+ int_perc+ "% is " +df.format(tax));}}Makes it slightly more automatizated. ;-)
Variations are possible. I personally used a slighty different code here:
ReplyDeleteimport java.text.DecimalFormat;
public class Exercise6 {
public static void main(String[] args){
double total = 197.55;
double tax;
double interest = 0.06;
double int_perc = interest*100;
tax = total * interest;
DecimalFormat df = new DecimalFormat("#.##");
System.out.println("Sales tax for purchase amount of " +total+ " @ "+ int_perc+ "% is " +df.format(tax));
}
}
Makes it slightly more automatizated. ;-)