I have used a method similar to g.mccormick's response for creating a flow totalizer from a flow rate input. There are a couple of things I'd specify:
1. If at all possible, place this logic in a timed task rather than using a timer, especially if this value is of a critical nature.
2. If using floating point, adding a relatively small value to a relatively large value can be problematic. To overcome this, use an intermediate integral (one that counts to say 1, 10 or 100) then when this preset is reached, subtract that preset amount from your intermediate integral value and add it to your main integral.