I have a difficult math question that breaks my brain, my board and all my pens. I am working with a file that expresses 2 values, multipicand and percentage . Both of these values must be integers. These two values are multiplied together to create a range. . Range is the value of the float.
My users are editing the range, and I have to calculate the new percentage and value of the animation. Not confused yet? Here is an example:
Multiplicand: 25,000 Apples
Percentage: 400 (This works out to .4% or .004)
Range: 100.0 Apples (Calculated by Multiplicand * Percentage)
To complicate matters, the valid values for Percentage are 0-100000. (Value 0-100%) Multiplicand is a value from 1 to 32 bits int max (presumably unsigned).
I need to allow users to enter a range, for example:
Range: .04 Apples
And calculate the appropriate percentages and animations. Using the first example:
OriginalMultiplicand: 25000 Apples
OriginalPercentage: 400 (This works out to .4% or .004)
OriginalRange: 100.0 Apples (Calculated by Multiplicand * Percentage)
NewRange: .01 Apples
NewPercentage: 40
NewMultiplicand: 25 Apples
The calculation example is simple, all that was required was a multiplier adjustment and a percentage down the scale factor of the new and old range. The problem occurs when the user changes the value to approximately 1400.00555. Suddenly, I have no clean way to adjust the two values.
I need an algorithmic approach to get the values for M and P that give the highest possible value for the required range. Any suggestions?
Phill
source share