Nova 5 sumByDays Rounds Decimal Values Unexpectedly in Trend Metrics
- Dominant language
- No language data
- Stars
- 557
- Forks
- 33
- PR merge metrics
- No merged PRs in 30d
Description
• Laravel Version: 11.0
• Nova Version: 5.x
• PHP Version: 8.2
• Database Driver & Version: MySQL 8.0
• Operating System and Version: macOS 14.3
• Browser type and version: Chrome 120
• Reproduction Repository: N/A
Description:
When using the sumByDays method in a Nova Trend metric, the returned trend values appear to be rounded, despite the database storing decimal values with two decimal places.
For example, the database contains:
[
{ "date": "2025-01-06", "total_fee": "0.68" },
{ "date": "2025-01-21", "total_fee": "0.60" }
]
However, when calling sumByDays, the returned values seem to be rounded, causing the metric chart to display incorrect results. The issue persists even after setting the format method to enforce decimal precision:
->format(['thousandSeparated' => true, 'mantissa' => 2])
Detailed steps to reproduce the issue on a fresh Nova installation:
1. Create a Nova metric using sumByDays:
```php
public function calculate(NovaRequest $request): TrendResult
{
return $this->sumByDays(
$request,
BillOrder::where('pay_status', \Infodev\Payment\Models\BillOrder::PAY_STATUS_PAYED),
'fee',
'pay_time'
)->prefix('$')->suffix(' AUD')->format(['thousandSeparated' => true, 'mantissa' => 2]);
}
```
2. Ensure the fee column is stored as DECIMAL(10,2).
3. Verify the database values contain two decimal places.
4. Dump $result->trend before returning the response:
dd($result->trend);
5. Observe that the values are rounded, despite expecting two decimal places.
Question:
• Is there an internal rounding mechanism applied in sumByDays?
• How can we enforce decimal precision without rounding in sumByDays?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided Nova Trend metric reproduction and inspect the value of $result->trend after sumByDays and after format(). Compare those values with the stored DECIMAL(10,2) records. Done means determining where the rounding occurs and documenting a confirmed reproduction or resolution; no source files or tests are named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, mysql, php
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100