Laravel Tutorials

Currency Formatting with Laravel's Enhanced Number Helper

Published
Currency Formatting with Laravel's Enhanced Number Helper image

Laravel's Number helper now supports configurable default currencies, simplifying price formatting across different regions and use cases. This enhancement is particularly valuable for applications serving international customers or handling transactions in multiple currencies. Instead of manually managing currency symbols and formats, you can now leverage Laravel's built-in formatting with configurable defaults.

use Illuminate\Support\Number;
// Set application-wide default
Number::useCurrency('EUR');
// Format with default
$price = Number::currency(1000); // €1,000.00
// Temporary override
$usdPrice = Number::currency(1000, in: 'USD'); // $1,000.00

Here's an example of implementing a multi-regional checkout system:

<?php

namespace App\Services;

use App\Models\Order;
use Illuminate\Support\Number;

class PricingService
{
    public function formatOrderPrices(Order $order, string $displayCurrency)
    {
        return Number::withCurrency($displayCurrency, function() use ($order) {
            return [
                'subtotal' => Number::currency($order->subtotal),
                'tax' => Number::currency($order->tax),
                'shipping' => Number::currency($order->shipping_cost),
                'total' => Number::currency($order->total),
                'savings' => $this->calculateDiscounts($order)
            ];
        });
    }

    private function calculateDiscounts(Order $order): array
    {
        return [
            'bulk_discount' => Number::currency($order->bulk_discount),
            'loyalty_savings' => Number::currency($order->loyalty_discount),
            'total_saved' => Number::currency(
                $order->bulk_discount + $order->loyalty_discount
            )
        ];
    }
}

The Number helper's enhanced currency formatting capabilities streamline multi-currency support in Laravel applications. It provides flexibility for both application-wide defaults and context-specific currency formatting, making it easier to handle international pricing requirements.

Harris Raftopoulos photo

Senior Software Engineer • Staff & Educator @ Laravel News • Co-organizer @ Laravel Greece Meetup

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Generate Laravel Validation Rules From a JSON Schema image

Generate Laravel Validation Rules From a JSON Schema

Read article
Laravel Suspicious Login: Detect and Block Risky Logins image

Laravel Suspicious Login: Detect and Block Risky Logins

Read article
Decide with Jev: Make Failed AI Requests Safe in Laravel image

Decide with Jev: Make Failed AI Requests Safe in Laravel

Read article
Black Friday: Learn the habits behind AI workflows that work image

Black Friday: Learn the habits behind AI workflows that work

Read article
Laravel Black Friday and Cyber Monday Deals 2026 image

Laravel Black Friday and Cyber Monday Deals 2026

Read article
pgjumbo: A PostgreSQL Client for macOS, Windows, and Linux image

pgjumbo: A PostgreSQL Client for macOS, Windows, and Linux

Read article