-
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
Price bucket rounding error. #2350
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I'm currently trying to see if I can figure out why this is happening. Adding 2.550000 to the cpmInputs and {"low":"2.50","med":"2.50","high":"2.55","auto":"2.55","dense":"2.55","custom":""} to the priceStringOutputs in the cpmInputsOutputs.json file causes the "getPriceBucketString function generates the correct price strings" test to fail. Probably obvious, but this is the line of code where things are going wrong: I've tried a couple different formulas and they get close but still aren't quite right and cause some failing tests. Here's what I've tried: |
From investigating further, the issue appears to be how dividing with decimals is handed in JavaScript. For example, when you divide When the I've found an adjustment to the formula that appears to work, by doing a precision rounding to 3 decimal places on the quotient before applying the floor. The precision rounding logic I plan to use was found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round#A_better_solution This modifies the value to the expected state for the rest of the formula to place the cpm in the ideal bucket. I'm doing some further analysis on various cpms/increment values to see if it's consistently working, as well as checking the results when using the standardized buckets (ie |
Update on the previously noted solution. Based on further analysis, we've decided to implement a different solution that was found to be more efficient performance-wise. We will multiply the individual values of the formula that gets floored (ie see https://jsperf.com/cpm-bucket-rounding/ to the unit test comparison. |
resolved. |
Type of issue
bug
Description
When using this price granularity:
A bid price of 4.01000 is rounded down to 4.00. It should be rounded to 4.01
The text was updated successfully, but these errors were encountered: