Skip to content
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

Percent change division by zero warnings #39

Closed
pderksen opened this issue Oct 11, 2016 · 1 comment
Closed

Percent change division by zero warnings #39

pderksen opened this issue Oct 11, 2016 · 1 comment

Comments

@pderksen
Copy link

Not sure what caused this but I noticed some division by zero PHP warnings in my server logs on my production site from yesterday (running v0.5.0). Example:

[Mon Oct 10 16:41:20.579279 2016] [:error] [pid 7810] [client 209.136.228.130:20256] PHP Warning: Division by zero in .../wp-content/plugins/edd-metrics/includes/class-edd-metrics-functions.php on line 392, referer: .../wp-admin/edit.php?post_type=download&page=edd_metrics

Somehow the $old_val passed in here was zero?

public static function percent_change($new_val, $old_val) {
if( empty( $old_val ) )
return 0;
// Commas break this equation
$new_val = str_replace( ',', '', $new_val );
$old_val = str_replace( ',', '', $old_val );
return ( ( $new_val - $old_val ) / $old_val ) * 100;
}

Sorry I can't narrow it down more than that right now.

@scottopolis
Copy link
Owner

Should hopefully fix ecefd29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants