Need formula the rounds values, and ensures rounded value sum still equals original value sum

tommyk203

New Member
Joined
Nov 24, 2015
Messages
13
I cant figure out how to write a formula that will round a group of numbers (original data) that equal a whole number (10 in this case), and have the rounded numbers still equal the original sum. You can see the the rounded data equals 9, when I would like it to equal 10. I've tried round up, down, etc, on larger sets of data, but it inevitably ends up being wrong. Any thoughts on how to fix this?
sample spreadsheet - Rounding Problem


original datarounded datacorrected rounded data
1.4545454551
4.047846894
3.3301435413
1.1674641151
10910
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I think that you might struggle to find an answer for this. It looks like you need to use something known as 'Bankers rounding'.

The most accurate methods for this all use vba, which is something that can not be used with google sheets. You might be able to find something by searching but so far I have not seen anything that I would recommend as being useful.
 
Upvote 0
=ArrayFormula({"Reallocated shots to level 1";IF(A3:A="",,INT(A3:A/$A$2*$A$1)+IF(VLOOKUP(ROUND(A3:A/$A$2*$A$1,3),{SORT(ROUND(A3:A/$A$2*$A$1,3),(A3:A/$A$2*$A$1)-INT(A3:A/$A$2*$A$1),0),SEQUENCE(ROWS(A3:A),1)},2,FALSE)<=($A$1-SUM(INT(A3:A/$A$2*$A$1))),1,0))})
 
Upvote 0
Solution
A different approach which I found convenient because it minimizes the absolute error:
sbRoundToSum.xlsm
ABCDEFGH
1bAbsSumTRUETotal objective
2Decimals to round to:0Difference to rounded
3Absolute valuesRelative valuesRounded valuesErrorRank of10,0000Result
4Total10,0000100,00009,0000error1,000010,0000
511,45454545514,54551,0000-0,454511,00002,0000
624,0478468940,47854,0000-0,047840,00004,0000
733,33014354133,30143,0000-0,330120,00003,0000
841,16746411511,67461,0000-0,167530,00001,0000
RoundToSum
Cell Formulas
RangeFormula
G3G3=ROUND(IF($D$1,SUM(B5:B8),SUM(C5:C8)),$D$2)
H4,B4:D4B4=SUM(B5:B8)
G4G4=G3-D4
C5:C8C5=B5/$B$4%
D5:D8D5=ROUND(IF($D$1,B5,C5),$D$2)
E5:E8E5=D5-IF($D$1,B5,C5)
F5:F8F5=COUNTIF($E$5:$E$8,IF($G$4>0,"<",">")&$E5)+COUNTIF($E$5:$E5,$E5)
G5:G8G5=IF(F5<=ROUND(ABS($G$4*10^$D$2),0),SIGN($G$4)*10^-$D$2,0)
H5:H8H5=D5+G5
 
Upvote 0
A different approach which I found convenient because it minimizes the absolute error:
sbRoundToSum.xlsm
ABCDEFGH
1bAbsSumTRUETotal objective
2Decimals to round to:0Difference to rounded
3Absolute valuesRelative valuesRounded valuesErrorRank of10,0000Result
4Total10,0000100,00009,0000error1,000010,0000
511,45454545514,54551,0000-0,454511,00002,0000
624,0478468940,47854,0000-0,047840,00004,0000
733,33014354133,30143,0000-0,330120,00003,0000
841,16746411511,67461,0000-0,167530,00001,0000
RoundToSum
Cell Formulas
RangeFormula
G3G3=ROUND(IF($D$1,SUM(B5:B8),SUM(C5:C8)),$D$2)
H4,B4:D4B4=SUM(B5:B8)
G4G4=G3-D4
C5:C8C5=B5/$B$4%
D5:D8D5=ROUND(IF($D$1,B5,C5),$D$2)
E5:E8E5=D5-IF($D$1,B5,C5)
F5:F8F5=COUNTIF($E$5:$E$8,IF($G$4>0,"<",">")&$E5)+COUNTIF($E$5:$E5,$E5)
G5:G8G5=IF(F5<=ROUND(ABS($G$4*10^$D$2),0),SIGN($G$4)*10^-$D$2,0)
H5:H8H5=D5+G5
Thanks. Anyway to get all of that in a single column so we dont need so many helper columns?
 
Upvote 0
Google for excel round summands to rounded sum, or for vba round summands to rounded sum.

TCRound is a commercial approach, Gustav Brock's solution is free of charge, as is mine.
 
Upvote 0

Forum statistics

Threads
1,223,602
Messages
6,173,294
Members
452,509
Latest member
CSHOCK

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