# Thread: Problem when multiplying integers

1. ## Problem when multiplying integers

Hello,

I need to multiply a price by a quantity. I'm using the following:
intTotal = (int(strPrice) * int(strQuantity))
strPrice contains the value 20.80 and strQuantity contains the value 10
It gives me a total of \$200 when it should be \$208. Why does it discard the .80 cents in the multiplication? What can I do to fix it?

Thank you very much!

Julie F.

2. change it to
intTotal = (cint(strPrice) * cint(strQuantity))

3. Ok, it now multiplies the decimals but it rounds it up to the highest dollar. Example, if the answer is supposed to be \$41.30, it rounds it up to \$42. How can I prevent it from rounding up my numbers?

Thanks a lot for your help!

Julie F.

4. Um, stuff with decimals should not be coerced/cast to be an integer (int), because by definition an integer is a whole number.

try

total = CDbl(strPrice) * CDbl(strQuantity)

5. With the CDbl, it wouldn't display the trailing zero (it would display \$40.8 instead of \$40.80). After making a few more searches, I tried CCur but that did the samething. Finaly, I solved the issue with this:

subtotal = CCur(strPrice) * CCur(strQuantity)
<% = FormatCurrency(subtotal,2) %>

Thanks and happy holidays!

Julie F.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•