Laravel Utilities

Format Currencies, Percentages, and Ordinals with the Number Utility

Punyapal Shah 1 min read
edit this tip
Use Laravel's Number utility class to format numbers into localized currencies, percentages, and spelled-out words.

Formatting numbers for localized user interfaces traditionally required configuring PHP's NumberFormatter extension manually.

Laravel provides the Illuminate\Support\Number utility class.

Formatting Currencies

use Illuminate\Support\Number;

echo Number::currency(1500, in: 'USD');
// "$1,500.00"

echo Number::currency(2490.50, in: 'EUR', locale: 'de');
// "2.490,50 €"

echo Number::currency(50000, in: 'INR');
// "₹50,000.00"

Formatting Percentages and Compact Numbers

// Percentages
echo Number::percentage(0.854, precision: 1);
// "85.4%"

// Compact abbreviated numbers
echo Number::abbreviate(1250000);
// "1.3M"

echo Number::abbreviate(4500);
// "4.5K"

Spelling Out Numbers and Ordinals

echo Number::spell(42);
// "forty-two"

echo Number::ordinal(3);
// "3rd"

Summary

  • Formats localized currency amounts with ISO 4217 codes.
  • Abbreviates large numbers into human-readable notation (e.g. 1.2M, 500K).
  • Spells out integer counts and ordinal positions for natural UI copy.
Tags: Laravel Formatting Utilities Localization
Share on X

// Found an issue or want to contribute a tip? github.com/MrPunyapal/tips