• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Multiplication throwing incorrect results

Shailender

Member
Hello All,
I am trying to do multiplication with the help of VBA code instead of using excel formula. But the strange thing is I am getting two different results when I run through macro and excel. I would like to know the difference. Please find the attached excel sheet.

Excel Result- 3002
Macro Result - 3034
 

Attachments

  • Book1.xlsm
    15.3 KB · Views: 2
Shailender
by 'Excel': C2=40,73 D2 =73,71 ((40,73*73,71= 3002,2083
by 'Your Macro': with LONG C2=41 and D2=74 ((41*74= 3034))
and there, You're using also Round-function (no effect)
 
Vletm, thank you for your quick response. By Excel in C2 & D2 it is to be 40.73 & 73.71 not (C2=40,73 D2 =73,71). In the above answer you have mentioned the differences. Which is the one correct?
 
ok Vletm. One last question is it right the both answers will vary? I mean when we perform the calculations through Excel formulas & VBA the result we get is different right?
 
Shailender
oh!!
You didn't get an idea ... or ... hmm?
Someway both solutions are correct ... BUT ...
You should know... what do You do and what do You want!
If You use exact values then You'll get result with exact values.
If You use 'rounded' values (as LONG ... no decimals), then You'll get result with 'rounded' values.
Excel will always calculate correct way (or as it works)!
Sometimes users write something, which give unwanted results.

If You will uses 'rounded' values for many times for many steps then the final results would be (total) different!
That's why ... 'round' values ONLY once and ONLY with the final result!

If You use 'totally wild' type with Your sample eg 'Boolean' then then the result would be ... interesting.
As well as ...
If I would ask 1 Bitcoin from every answer, instead 1 INR
... there also would be some differences (gotta be careful with types!)
 
Back
Top