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

Nova 5 sumByDays Rounds Decimal Values Unexpectedly in Trend Metrics #6728

Open
brookbnu opened this issue Feb 8, 2025 · 1 comment
Open
Labels
documentation Documentation issue

Comments

@brookbnu
Copy link

brookbnu commented Feb 8, 2025

•	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:

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?

@brookbnu
Copy link
Author

brookbnu commented Feb 8, 2025

in function calculate set

$this->roundingPrecision = 2;

@crynobone crynobone added the documentation Documentation issue label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation issue
Projects
None yet
Development

No branches or pull requests

2 participants