-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix cpm floor issue in price bucket formula #2644
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkendall07
reviewed
May 30, 2018
src/cpmBucketManager.js
Outdated
// force to 10 decimal places to deal with imprecise decimal/binary conversions | ||
// (for example 0.1 * 3 = 0.30000000000000004) | ||
cpmTarget = Number(cpmTarget.toFixed(10)); | ||
return cpmTarget.toFixed(precision); | ||
} | ||
|
||
function round(number, precision) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should link the source for this function.
mkendall07
approved these changes
May 30, 2018
mkendall07
added
LGTM
needs 2nd review
Core module updates require two approvals from the core team
labels
May 30, 2018
snapwich
approved these changes
May 31, 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Pupis
pushed a commit
to adform/Prebid.js
that referenced
this pull request
Jun 7, 2018
* fix cpm rounding issue in price bucket formula * switch logic to exponent variant instead of precision rounding * update min precision to 2 for exponent * fixed addition
dluxemburg
pushed a commit
to Genius/Prebid.js
that referenced
this pull request
Jul 17, 2018
* fix cpm rounding issue in price bucket formula * switch logic to exponent variant instead of precision rounding * update min precision to 2 for exponent * fixed addition
ghost
pushed a commit
to devunrulymedia/Prebid.js
that referenced
this pull request
Jan 30, 2019
* fix cpm rounding issue in price bucket formula * switch logic to exponent variant instead of precision rounding * update min precision to 2 for exponent * fixed addition
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.