Rounding To 2 Decimal Places
-
How do I code this to round my results to 2 decimal places? Module Module1 Dim itemQuantity As Integer = 0 Dim itemPrice As Decimal = 0 Dim totalSales As Decimal = 0 Dim stateName As String Dim taxRate As Decimal = 0 Dim taxAmount As Decimal = 0 Dim customerName As String Sub Main() Console.WriteLine("Please enter your name.") customerName = Console.ReadLine() Console.WriteLine("Please enter your state: NJ, FL, or NY") stateName = Console.ReadLine() Console.WriteLine("Please enter the number of items purchased.") itemQuantity = Console.ReadLine() Console.WriteLine("Please enter the price of the item.") itemPrice = Console.ReadLine() Call computeTotal() Call computeTax() Console.WriteLine("The total sales for " & customerName & " are " & totalSales & " .") Console.WriteLine("The tax amount is " & taxAmount & " based on a tax rate of " & taxRate & " .") Console.WriteLine("The total with tax is " & totalSales + taxAmount & " .") Console.ReadLine() End Sub Function computeTotal() As Decimal totalSales = itemQuantity * itemPrice Return totalSales End Function Function computeTax() As Decimal If stateName = "NJ" Then taxRate = 0.07 ElseIf stateName = "FL" Then taxRate = 0.06 ElseIf stateName = "NY" Then taxRate = 0.04 End If taxAmount = totalSales * taxRate Return taxAmount End Function End Module
-
How do I code this to round my results to 2 decimal places? Module Module1 Dim itemQuantity As Integer = 0 Dim itemPrice As Decimal = 0 Dim totalSales As Decimal = 0 Dim stateName As String Dim taxRate As Decimal = 0 Dim taxAmount As Decimal = 0 Dim customerName As String Sub Main() Console.WriteLine("Please enter your name.") customerName = Console.ReadLine() Console.WriteLine("Please enter your state: NJ, FL, or NY") stateName = Console.ReadLine() Console.WriteLine("Please enter the number of items purchased.") itemQuantity = Console.ReadLine() Console.WriteLine("Please enter the price of the item.") itemPrice = Console.ReadLine() Call computeTotal() Call computeTax() Console.WriteLine("The total sales for " & customerName & " are " & totalSales & " .") Console.WriteLine("The tax amount is " & taxAmount & " based on a tax rate of " & taxRate & " .") Console.WriteLine("The total with tax is " & totalSales + taxAmount & " .") Console.ReadLine() End Sub Function computeTotal() As Decimal totalSales = itemQuantity * itemPrice Return totalSales End Function Function computeTax() As Decimal If stateName = "NJ" Then taxRate = 0.07 ElseIf stateName = "FL" Then taxRate = 0.06 ElseIf stateName = "NY" Then taxRate = 0.04 End If taxAmount = totalSales * taxRate Return taxAmount End Function End Module