By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

VB Multiplication

P: 1

I'm trying to multiply two numbers together within VB and am getting the incorrect result

My code has the following....
dblDirectRes = dblDirect * dblMultDirect
All variables are defined as Doubles
dblDirect = 219558400 and dblMultDirect = 0.9123

dblDirectRes is calculated by VB to equal 200303126, but it SHOULD be 200303128.

I understand there are some issues with VB's calculation methods. Could anyone suggest a multiplication method to get the correct result?
Sep 5 '07 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 807
Actually, the correct answer is 200303128.32 which is what VB gives. Are you sure they are doubles? You can get four decimal places by declaring them as Currency, but with small numbers (small defined as less than a trillion) such as yours, the results are the same.
Expand|Select|Wrap|Line Numbers
  1. Sub Macro1()
  2.     Dim dblDirect As Double
  3.     Dim dblMultDirect As Double
  4.     Dim dblDirectRes As Double
  5.     dblDirect = 219558400
  6.     dblMultDirect = 0.9123
  7.     dblDirectRes = dblDirect * dblMultDirect
  8.     MsgBox dblDirectRes
  9. End Sub
Sep 5 '07 #2

Expert 100+
P: 1,445

Yes the Correct Answer is :
What type of Variable have u declared dblDirectRes ..?
If u have declared it as LONG, then the dec would have been Truncated.
Check how u have declared, other variables also..

Sep 5 '07 #3

P: 59
What you're trying to do is:

4 = 4 * 5

What you have to do is:

(empty variable) = 4 * 5

So sammy hit the nail on the head

(not that she needs to be told that she had it 100% correct)

BTW, I didn't thing that "long"'s have decimal places??
Sep 5 '07 #4

Expert 5K+
P: 8,434
What you're trying to do is:

4 = 4 * 5
How do you get that from dblDirectRes = dblDirect * dblMultDirect? KenNeal's code looks perfectly alright to me.

... BTW, I didn't thing that "long"'s have decimal places??
They don't. That's why QVeen72 said it would be truncated.

Though technically, I think it would be rounded, not truncated.
Sep 6 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.