Skip to content

Laravel Number helper format numbers as 1.2K, 3M, file sizes

PHP Dasun Kalupahana 221 views

<?php

use Illuminate\Support\Number;

Number::abbreviate(1_250_000);        // "1M"
Number::abbreviate(1_250_000, 1);     // "1.3M" (precision 1)
Number::currency(1234.5, 'USD');      // "$1,234.50"
Number::fileSize(1024 * 1024 * 5);    // "5 MB"
Number::percentage(45.5, precision: 1); // "45.5%"

Built-in formatting for abbreviations, currency, file sizes and percentages, so you don’t need to write helpers. Use it in views and API responses. Needs Laravel 10.x+ (the Number class).

Learn more on the blog

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.