Storage of leftover values in a situation of having to round down
Posted
by
jt0dd
on Programmers
See other posts from Programmers
or by jt0dd
Published on 2014-05-31T23:01:39Z
Indexed on
2014/06/01
3:47 UTC
Read the original article
Hit count: 221
I'm writing an app (client and server side) where the number of sales required by each employee must be kept track of in round-number form. Each month, the employees are required to sell a certain number, and this app needs to keep track of how many sales must be made for each 12 hour interval during the work week.
Because I have to round the values down to a whole number, I must keep track of leftovers in the rounding process and ensure that they are always carried over. My method must ensure the storage of the leftover value even when client and server side crash, restart, close, etc.
Right now, I'm working on doing this by storing the leftovers in a field in the user's account row in the database each time a value is rounded, reading the stored value, removing any portion that is used (when a whole number is reached, most of the leftover is used up), and storing the new value.
This practice seems weird because while the leftovers are calculated on the client side, it's the same number for each employee, and every employee using the app is storing a copy of the same leftover data. Alternatively, I could have all clients store the data at once into the same data field on a general table, but this is just as weird.
Is there a better way that this can be handled or is my method correct?
© Programmers or respective owner