How do you calculate a percentage? Here is an example:
1. If you want to give a
10% discount from
$100.00 the calculation is:
discount amount = value * (discount / 100)
= 100.00 * (10 / 100)
= 100.00 * 0.10
= 10.00
2. To calculate the net amount, ie, the discounted amount, you can do it 2 ways:
discounted amount = value - (value * (discount / 100))
= 100.00 - (100.00 * (10 / 100))
= 100.00 - (100.00 * 0.10)
= 100.00 - 10.00
= 90.00
or ...
discounted amount = value * (ABS(100 - discount) / 100)
= 100.00 * (ABS(100 - 10) / 100)
= 100.00 * (90 / 100)
= 100.00 * 0.90
= 90.00
where
ABS[
^] is the positive of a value.
This should make it easy to modify your code.
UPDATE
As Dave pointed out in the comments below, you need a valid number in the
TextBox
, then you need to convert it to a number value. I'm going to use a
Double
to support decimals:
Dim testText1 = "10.5"
Dim testText2 = "bad_10.5"
Dim value1 As Double
Dim value2 As Double
If Double.TryParse(testText1, value1) Then
MsgBox(value1)
Else
MsgBox("bad text")
End If
If Double.TryParse(testText2, value2) Then
MsgBox(value2)
Else
MsgBox("bad text")
End If
The above example shows how to parse and test text to a number. I will leave it to you to update your code.