Home All Groups Group Topic Archive Search About
Author
14 Feb 2006 10:39 PM
DAL
I have two textboxes. One is to enter the percentage rate, and the other
text box is to enter the price of the item. What is the formula to get the
correct answer after the percentage has been subtracted from the original
price.

Example: 10% of $1 = .90

Thank you in advance, DAL.

Author
14 Feb 2006 10:53 PM
jreid
Try this.

Dim prcnt as Integer = cint(txtPercent)
Dim price as Integer = cint(txtPrice)

Dim Xnum as Integer = (100 - prcnt )/100

txtFinalPrice.Text = price * Xnum

Pretty much what your doing is subtracting the entered percentage from
100 and then dividing that from 100. Then multiplying that by the
price.

Example:

100% - 10% = 90%
90/100 = .9

..9 X $1 = .90

Hope this helps,
Jeremy Reid
http://blackstaronline.net/hgtit
Author
15 Feb 2006 8:07 AM
Don
Sorry to butt in but . . . , you can't use integers to calculate
percentages unless you significantly modify the approach.

    Don

On 14 Feb 2006 14:53:52 -0800, jr***@blackstaronline.net wrote:

Show quoteHide quote
>Try this.
>
>Dim prcnt as Integer = cint(txtPercent)
>Dim price as Integer = cint(txtPrice)
>
>Dim Xnum as Integer = (100 - prcnt )/100
>
>txtFinalPrice.Text = price * Xnum
>
>Pretty much what your doing is subtracting the entered percentage from
>100 and then dividing that from 100. Then multiplying that by the
>price.
>
>Example:
>
>100% - 10% = 90%
>90/100 = .9
>
>.9 X $1 = .90
>
>Hope this helps,
>Jeremy Reid
>http://blackstaronline.net/hgtit
Author
15 Feb 2006 4:39 PM
jreid@blackstaronline.net
Whoops, my bad, Thanks for catching that. Don is absolutely correct.
Integer data type is NOT what you would want to use to calculate that
equation.

Sorry for leading you down the wrong path....my bad.


Jeremy Reid
http://blackstaronline.net/hgtit