432,035 Members | 1,543 Online
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 Hi, 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
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 Sub Macro1()     Dim dblDirect As Double     Dim dblMultDirect As Double     Dim dblDirectRes As Double     dblDirect = 219558400     dblMultDirect = 0.9123     dblDirectRes = dblDirect * dblMultDirect     MsgBox dblDirectRes End Sub   Sep 5 '07 #2

 Expert 100+ P: 1,445 Hi, Yes the Correct Answer is : 200303128.32 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.. REgards Veena 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