PDA

View Full Version : Target to Cost Question



kepidogo
05-02-2020, 01:48 PM
I have some code that targets a task to a desired cost. It adjusts each resource assignment using a ratio of the desired cost over current cost. In general, it works great except in a very specific situation.

If the delta between the current cost and desired cost is very small, it is almost impossible to get the cost to the exact penny. It ends up being 1 or 2 cents above or below. Every time you run it, it flip flops between being 1-2 cents high and 1-2 cents low.

I have tried changing the current cost, the number of units, and the initial cost at the beginning to achieve a greater delta so that it will work but the results are mixed.

Does anyone know of a way to ensure that you can target to cost the first time every time?

SamT
05-02-2020, 02:25 PM
Maybe try: Change all your "Double" variables to "Currency" variables.

Uncertainty like that is a known issue of digitized math.

Alternately, Round the result of every step of every calculation to the fifth decimal place.