Alright, heres the deal: For some reason the program rounds my answers up. If the total is $3.65, it outputs $4. The program deals with sales so its gotta be precise. I cant figure it out how to make to show the exact price with the change and not round up.
decSubTotal = SelectPhone() * txtNumberOfPhones.Text
decTax = decSubTotal * intTAX_RATE
decTotal = SelectOption() + SelectPackage()
lblSubTotal.Text = FormatCurrency(decSubTotal, 2)
lblTax.Text = FormatCurrency(decTax)
lblTotal.Text = FormatCurrency(decSubTotal + decTax)
lblOptions.Text = FormatCurrency(SelectOption())
lblPackageCharge.Text = FormatCurrency(SelectPackage())
lblTotalCharges.Text = FormatCurrency(decTotal * txtNumberOfPhones.Text)
Jan MontanoPosted Oct 30, 2007, 2:01 AM
If it's still rounding up... hmm... I have no idea what's causing it. Perhaps others could help us. HELP!!!! (^_^)
Sonny ThaiPosted Oct 26, 2007, 3:08 AM
Wow, thats cool how you got to set up a program with matching lbl names and all. However, I am still getting rounded numbers :(. Heres the gist of the program. I need to create a program with 3 forms.
The main one is the where the user can either choose the individual cell phone plan or the family cell phone plan.
The Family phone plan form consists of 3 models ranging from $29.95, $49.95, and $95.95, the number of phones of the same model they wish to purchase, the plan/minutes they wish to add ($45, $65, and $95), and the option of voicemail($5) & text ($10).
The individual plan is exactly the same as the family minus the choice of buying extra phones.
My output consists of six labels:
Phone subtotal: Which is the price of whatever model the user chooses on the individual program and what the price is of whatever thte user chooses times the amount of phones purchased.
Tax: Their is a 6% tax so I take 0.06 times the total of the Phone subtotal
Phone Total: which is the Phone subtotal + the Tax added together
Options: which adds the $5 Voicemail or the $10 Text if they choose it
Package Charge: The number of minutes they choose
Total Monthly Charges: which is the Options + Package Charge added together
BTW, I really do appreciate your help on this. Maybe we should exchange emails, since this post was so long. Up to you. Thanks again.
Jan MontanoPosted Oct 25, 2007, 10:46 PM
Hi,
I tried your code, but it doesn't round up on my end.
I assume intTAX_RATE is an integer. But do you only assign whole numbers to it? don't you assign percentage values to it? here's what I have so far. I just modified some items for test purposes. I have outputs
59.9
5.99
65.89
5
45
100
Let's see if you also come up with those numbers.
Public
Class Form1 Dim decSubTotal As Decimal Dim decTax As Decimal Dim decTotal As Decimal Dim dblTAX_RATE As Double = .1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'txtNumberOfPhones is 2
Main1()
End Sub Sub Main1()decSubTotal = SelectPhone() * txtNumberOfPhones.Text
decTax = decSubTotal * dblTAX_RATE
decTotal = SelectOption() + SelectPackage()
lblSubTotal.Text = FormatCurrency(decSubTotal, 2)
lblTax.Text = FormatCurrency(decTax)
lblTotal.Text = FormatCurrency(decSubTotal + decTax)
lblOptions.Text = FormatCurrency(SelectOption())
lblPackageCharge.Text = FormatCurrency(SelectPackage())
lblTotalCharges.Text = FormatCurrency(decTotal * txtNumberOfPhones.Text)
End Sub Function SelectPhone() As Decimal 'Computes the cost of phone model 'If radMod100.Checked = True Then Return 29.95D 'End If 'If radMod110.Checked = True Then 'Return 49.95D 'End If 'If radMod200.Checked = True Then 'Return 99.95D 'End If End Function Function SelectPackage() As Decimal 'Computes the cost of the phone package/minutes 'If rad300.Checked = True Then Return 45D 'End If ' If rad800.Checked = True Then 'Return 65D 'End If 'If rad1500.Checked = True Then ' Return 99D 'End If End Function Function SelectOption() As Decimal 'Computes the cost of either of the options Dim decCostOption As Decimal = 0 'If chkVM.Checked = True ThendecCostOption += 5D
'End If 'If chkTxt.Checked = True Then 'decCostOption += 10D 'End If Return decCostOption End FunctionEnd
ClassSonny ThaiPosted Oct 25, 2007, 12:26 PM
Im using functions. The numbers should never round up because the program deals with sales so its gotta be exact ( like $1.25 in change cant be rounded to $1 in change). I know its a simple problem, but its bugging the hell out of me that I cant figure this out.
Heres the code:
decSubTotal = SelectPhone() * txtNumberOfPhones.Text
decTax = decSubTotal * intTAX_RATE
decTotal = SelectOption() + SelectPackage()
lblSubTotal.Text = FormatCurrency(decSubTotal, 2)
lblTax.Text = FormatCurrency(decTax)
lblTotal.Text = FormatCurrency(decSubTotal + decTax)
lblOptions.Text = FormatCurrency(SelectOption())
lblPackageCharge.Text = FormatCurrency(SelectPackage())
lblTotalCharges.Text = FormatCurrency(decTotal * txtNumberOfPhones.Text)
End If End Sub Function SelectPhone() As Decimal 'Computes the cost of phone model If radMod100.Checked = True Then Return 29.95D End If If radMod110.Checked = True Then Return 49.95D End If If radMod200.Checked = True Then Return 99.95D End If End Function Function SelectPackage() As Decimal 'Computes the cost of the phone package/minutes If rad300.Checked = True Then Return 45D End If If rad800.Checked = True Then Return 65D End If If rad1500.Checked = True Then Return 99D End If End Function Function SelectOption() As Decimal 'Computes the cost of either of the options Dim decCostOption As Decimal = 0 If chkVM.Checked = True ThendecCostOption += 5D
End If If chkTxt.Checked = True ThendecCostOption += 10D
End If Return decCostOption End FunctionJan MontanoPosted Oct 25, 2007, 1:29 AM
What are the methods SelectOption() & FormatCurrency() for? Could we have a look at the code? At what line does the total value round up?
Thanks.