---
title: "Number formatting — Metrics for Laravel | Roundly"
description: "Present values as currency, percentages or abbreviated figures with formatUsing() — the raw numbers stay untouched alongside."
url: https://roundly-consulting.com/open-source/docs/metrics-for-laravel/formatting
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Metrics for Laravel](https://roundly-consulting.com/open-source/docs/metrics-for-laravel.md)

# Number formatting

formatUsing() takes a Closure(float): string and adds a formatted key to the result without changing the raw numbers — a chart plots the value, a label prints the string:

```php
use Illuminate\Support\Number;

Metrics::value()
    ->sum(Order::query(), 'total')
    ->formatUsing(fn (float $value): string => Number::currency($value, 'USD'))
    ->toArray();
// result.value => 1500.0, result.formatted => "$1,500.00"
```

## Trends and partitions

For trends and partitions the formatter runs on every point, and formatted becomes a map with the same keys:

```php
use Illuminate\Support\Number;

Metrics::trend()
    ->sum(Order::query(), 'total')
    ->daily()
    ->range('MTD')
    ->formatUsing(fn (float $value): string => Number::abbreviate($value))
    ->toArray();
// result.formatted => ['2024-06-01' => '12K', '2024-06-02' => '9K', ...]

Metrics::partition()
    ->count(User::query(), 'plan')
    ->formatUsing(fn (float $value): string => number_format($value).' users')
    ->toArray();
// result.formatted => ['pro' => '120 users', 'free' => '80 users']
```

- Value and Progress — value is formatted into a single formatted string.
- Trend — each trends bucket is formatted into a formatted map.
- Partition — each partitions value is formatted into a formatted map.

prefix() and suffix() are separate, lighter presentation hints: they travel in the envelope untouched, for your front-end to place around the number. Laravel’s Number helpers require the intl PHP extension.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/metrics-for-laravel.md)
