fix cpm floor issue in price bucket formula #2644
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Description of change
To fix the issue reported in #2350
Summary of issue/change (taken from thread in that issue):
The issue appears to be how dividing with decimals is handed in JavaScript. For example, when you divide
4.01 / 0.01
in a calculator you would get401
. However if you do the same thing in JavaScript (easily see this in the browser console), you get400.99999999999994
. There are numerous sets of values that result in this manner, either slightly higher or lower than the expected mark (eg1.11 / .01 = 111.00000000000001
).When the
Math.floor
gets applied to these low rogue values, it'll reduce it down one level below it's expected value. So400.99999999999994
becomes400
, which is how we ultimately see a4.01
cpm end up in the4.00
cpm bucket when we have0.01
increments.I've found an adjustment to the formula that appears to work. We multiply the individual values of the formula that gets floored (ie
(cpm - bucketPrice) / increment
by exponential base of 10 (eg100000
) to avoid doing the math with decimals which avoids any rounding issues.update - we switched to this alternate logic as it was seen to be more efficient than the previous precision-rounding solution. See https://jsperf.com/cpm-bucket-rounding/ to the unit test comparison.