Excel VBA adding appears to be rounding values that I'm adding??

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
All my variables are Doubles.
I have formula like: a X b = Calculated_Value
Then I keep a running total of the Calculated_Values: TotalValuesCombined = TotalValuesCombined + Calculated_Value
TotalValuesCombined = 140395826 (what VBA has calculated)
If I dump all values to spread sheet and manullay sum them, they sum to 137046355.3
What can I do about this? Like said, all variables are doubles. I think the adding is some how rounding and adding; is there a way to make it stop?
 
Thanks. Yes, the code you've shown is perfectly clear. The code not shown is the unknown.

Did you try my test code? That will dump the values of btu_calc into Excel. If you SUM() these in Excel you should get 140,395,826 , i.e. the same as the VBA calc?

I did just now; as suspected, the variable (double) 'btu_calc', is reporting all values with 1 or 2 decimal places only; not 4-6 decimal places like the formula is outputting.
Still bizarre; any idea's?
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Sorry, not clear what you mean by reporting?

When the btu_calc values are dumped to Excel, they will display according to the format of the individual cells. But they should still have the full Excel precision.

What are the typical values being dumped? If they add up to 137 or 140 million, presumably we're not worried too much about what's after the decimal point?

Finally, what do the dumped values add up to using SUM()?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top