google / google/site-kit-wp

Email report change badge shows -0% for near-zero negative trends

Open Beginner friendly
#13,264 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Bug Description

When an email report metric's period-over-period change rounds to negative zero at one decimal place (e.g. an underlying change of `-0.03`), the HTML change badge and the plain text email both display `-0%` instead of a neutral `0%`.

PHP's `round( $value, 1 )` returns the float `-0.0` for such inputs, and string-casting `-0.0` produces the literal string `"-0"`, which is concatenated directly into the output in `includes/Core/Email_Reporting/templates/parts/change-badge.php` and `Plain_Text_Formatter::format_change()`.

Found while reviewing #12867 (the decimal-comma locale fix). It is not caused by that bug and is not required by its acceptance criteria, so it's filed here separately.

## Steps to reproduce

1. Trigger a weekly/monthly/quarterly email report where a metric's comparison to the previous period computes to a small negative percentage that rounds to zero at one decimal place (e.g. an underlying change of `-0.03`).
2. Generate the report and inspect the "Compared to previous X days" badge for that metric in both the HTML and plain text versions.
3. Observe the badge/text shows `-0%` instead of `0%`.

## Additional Context

- Plugin Version: 1.184.0

---------------

_Do not alter or remove anything below. The following sections will be managed by moderators only._

## Acceptance criteria

*

## Implementation Brief

### Files to modify

*

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Research direction

Start by reading includes/Core/Email_Reporting/templates/parts/change-badge.php and Plain_Text_Formatter::format_change(), the two output paths named in the report. Reproduce a report with a near-zero negative change and verify that both HTML and plain-text output show 0% rather than -0%; done means both formats display the neutral value.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.