- Thanks received
- 767
I have a number and I want to break it down into integers by %
but I want to guarantee that the sum of the breakdown equals the original number. i.e. if there is a rounding error, I want it corrected.
eg
number 998
10% = 100 (rounded up)
30% = 300 (rounded up)
30% = 300 (rounded up)
30% = 300 (rounded up)
for a total of 1000
I can do it the hard way. but is there a simple algorithm ?
![]()
HTH,
Joshi.

As it all boils down to 'reasonableness', there's probably some AI algorithm that would do it for you.number 998
10% = 100 (rounded up)
30% = 300 (rounded up)
30% = 300 (rounded up)
30% = 300 (rounded up)
for a total of 1000
I can do it the hard way. but is there a simple algorithm ?
![]()
veeeeeeeeeery quick answer cos hungry and glanced at thread
add all the rounded numbers up
=999
now you've got to loose 1 somewhere so choose the number with the fractional part closest to .5 and > 0.5 and zap it's fractional part
no repeat the adds of the rounded numbers and u get 998.
P.S. There might (probably) is a fairer way to "allocate" the zapping of the extra 1 but what I just scribbled might be a good way

you still haven't found your way to the pub then?aye, thats the logic all right. but I want the algorithm
![]()
veeeeeeeeeery quick answer cos hungry and glanced at thread
add all the rounded numbers up
=999
now you've got to loose 1 somewhere so choose the number with the fractional part closest to .5 and > 0.5 and zap it's fractional part
no repeat the adds of the rounded numbers and u get 998.
P.S. There might (probably) is a fairer way to "allocate" the zapping of the extra 1 but what I just scribbled might be a good way
the number of variables is an unknown
the % will be 2 dp
n will be an integer
![]()