Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MB's avatar
Level 2

Nova Trend Metric, number is divided by 1000

Hi,

I'm trying using Laraval Nova Trend Metric, but the output is wrong. Do you guys know why I get numbers like this 0.90k, 0.80k, 0.70k instead of 900, 800, 700 ?

Database screenshots here: https://imgur.com/a/Xk9qPbq

Nothing fancy added at all in my application.

Have tried to delete everything a few times, but the result always end up the same and I have absolutely no idea what is causing it :(

What can cause this problem? Any help is very much appreciated.

<?php

namespace App\Nova\Metrics;

use App\Models\Purchase;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Trend;

class PurchasesPerDay extends Trend
{
    /**
     * Calculate the value of the metric.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return mixed
     */
    public function calculate(NovaRequest $request)
    {
        return $this->sumByDays($request, Purchase::class, 'amount');
    }

    /**
     * Get the ranges available for the metric.
     *
     * @return array
     */
    public function ranges()
    {
        return [
            30 => __('30 Days'),
            60 => __('60 Days'),
            90 => __('90 Days'),
        ];
    }

    /**
     * Determine for how many minutes the metric should be cached.
     *
     * @return  \DateTimeInterface|\DateInterval|float|int
     */
    public function cacheFor()
    {
        // return now()->addMinutes(5);
    }

    /**
     * Get the URI key for the metric.
     *
     * @return string
     */
    public function uriKey()
    {
        return 'purchases-per-day';
    }
}

0 likes
4 replies
newbie360's avatar

900 to 0.90k in the meaning is true ;)

i haven't used Nova, so i can't answer this question, but for your question

if ($amount < 1000) {
    return $amount;
}

and what the expected value if 123456 123.45k or number_format(123456)

Maria30's avatar
Maria30
Best Answer
Level 20

@mb That division is right , simply because we count amounts of money per thousands.

You can experiment with the format you want by referring to Nova Docs: https://nova.laravel.com/docs/3.0/metrics/defining-metrics.html#value-result-formatting

To customize the display format, you can use the format method. The format must be a format supported by Numbro:

Example:

public function calculate(Request $request)
{
    return $this->count($request, User::class)
                ->format('0,0');
}
2 likes
MB's avatar
Level 2

That worked perfectly! Thanks a lot :)

Please or to participate in this conversation.