How to achieve 2 decimal places
- I have a point of sale calculator and i'm trying to achieve 2 decimal places in the results when the last digit is a zero.
I'm not sure which part of the code you might need either because i'm a student and i'm not very good with this kind of work, i'm just trying to learn. So here is everything I have as far as code.
Option
Explicit On
Public
Class Form1
Dim Tax = 0.06
Dim ItemN(5) As String, i As String
Dim Quant(5) As Integer
Dim Price(5) As Decimal, SubT As Decimal, Total As Decimal, PriceTotal(5) As Decimal
Private Function Check()
Check =
True
If IsNumeric(txtItemN.Text) Then
MsgBox(
"Invalid input text only", MsgBoxStyle.OkOnly, MsgBoxStyle.Information)
Check =
False
End If
If Not IsNumeric(txtQuant.Text) Then
MsgBox(
"Invalid input Numeric only", MsgBoxStyle.OkOnly, MsgBoxStyle.Information)
Check =
False
End If
If Not IsNumeric(txtPrice.Text) Then
MsgBox(
"Invalid input Numeric only", MsgBoxStyle.OkOnly, MsgBoxStyle.Information)
Check =
False
End If
End Function
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If Check() Then
Quant(i) =
CInt(txtQuant.Text)
Price(i) =
CDec(txtPrice.Text)
PriceTotal(i) = Price(i) * Quant(i)
SubT = SubT + PriceTotal(i)
Tax = Tax * SubT
Total = SubT + Tax
End If
ReceiptJournal.Items.Add((ItemN(i)) &
" " & CStr(Quant(i)) & " " & CStr(Price(i)) & " " & CStr(PriceTotal(i)))
lblSubT.Text = FormatCurrency(SubT)
lblTax.Text = FormatCurrency(Tax)
lblTotal.Text = FormatCurrency(Total)
Call ClearInputsOutputs()
i = i + 1
If i > 5 Then
MsgBox(
"Cannot exceed 5 Item purchase", MsgBoxStyle.OkOnly + MsgBoxStyle.Information)
Else
txtItemN.Text = ItemN(i)
End If
End Sub
Public Sub ClearInputsOutputs()
txtItemN.Text =
""
txtQuant.Text =
""
txtPrice.Text =
""
End Sub
Private Sub PointOfSale_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
i = 1
ItemN(1) =
"FirstItem"
ItemN(2) =
"SecondItem"
ItemN(3) =
"ThirdItem"
ItemN(4) =
"FourthItem"
ItemN(5) =
"FifthItem"
txtItemN.Text = ItemN(i)
Call ClearInputsOutputs()
End Sub
Private Sub ReceiptJournal_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReceiptJournal.SelectedIndexChanged
End Sub
Private Sub txtItemN_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtItemN.TextChanged
End Sub
End
Class


