PHPackages                             williamug/money-formatter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. williamug/money-formatter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

williamug/money-formatter
=========================

Comprehensive Laravel formatter package for money, percentages, file sizes, phone numbers, credit cards, durations, and more with Blade directives and helper functions

v3.0.3(3mo ago)12.5kMITPHPPHP ^8.2|^8.3|^8.4CI passing

Since May 10Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Williamug/money-formatter)[ Packagist](https://packagist.org/packages/williamug/money-formatter)[ Docs](https://github.com/williamug/money-formatter)[ RSS](/packages/williamug-money-formatter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (9)Versions (13)Used By (0)

Money Formatter
===============

[](#money-formatter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2b46ffa6cade801dbd6ec37a71430e6cb4174167deffb6f7d77f81e3357e7435/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77696c6c69616d75672f6d6f6e65792d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/williamug/money-formatter/stats#major/all)[![GitHub Tests Action Status](https://camo.githubusercontent.com/30cddf4074c5423a9363ec98a71b9404d2f860d8a2b934b13186cc3c2be3d87c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f77696c6c69616d75672f6d6f6e65792d666f726d61747465722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/williamug/money-formatter/actions?query=workflow%3Atests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/5cfa887141428d140726ee48a4999670124189ed9d83b8f3b515b24211492017/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77696c6c69616d75672f6d6f6e65792d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/williamug/money-formatter/)

**The ultimate Laravel formatting package** with 15+ formatters for money, percentages, file sizes, phone numbers, credit cards, durations, and more. Includes Blade directives, helper functions, and a fluent API with support for multiple currencies and locales.

Features
--------

[](#features)

**15+ Powerful Formatters**

- Money &amp; Currency formatting
- Percentage formatting
- File size (bytes to KB/MB/GB/TB)
- Number abbreviation (1K, 1M, 1B, 1T)
- Ordinal numbers (1st, 2nd, 3rd)
- Phone number formatting (international, national, dots)
- Credit card masking (secure)
- Duration formatting (seconds to human readable)
- Metric/SI prefix formatting
- Compact number notation
- Decimal to fraction conversion
- Number to words conversion
- And more!

**Multiple Ways to Use**

- Blade directives for templates (`@money`, `@percentage`, `@filesize`, etc.)
- Helper functions for quick usage (`format_money()`, `format_percentage()`, etc.)
- Facade for fluent API (`Money::format()`, `Money::percentage()`, etc.)
- Direct class instantiation for advanced usage

**Professional Features**

- Configurable decimal places, separators, and currency symbols
- Support for 8+ currencies (USD, EUR, GBP, UGX, KES, TZS, ZAR, and more)
- Locale-based formatting
- Parse formatted strings back to numbers
- Chainable methods for complex formatting

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
- PHP `intl` extension ([installation guide](https://www.php.net/manual/en/intl.installation.php))

Installation
------------

[](#installation)

Install the package via composer:

```
composer require williamug/money-formatter
```

### Publish Configuration (Optional)

[](#publish-configuration-optional)

Publish the configuration file to customize default settings:

```
php artisan vendor:publish --tag=money-formatter-config
```

This creates `config/money-formatter.php` where you can configure:

- Default locale and currency
- Decimal places and separators
- Currency symbols
- And more...

Usage
-----

[](#usage)

### Blade Directives

[](#blade-directives)

#### Format Money

[](#format-money)

```
@money(10000)
{{-- Output: 10,000.00 --}}

@money($invoice->total)
{{-- Output: 1,234.56 --}}
```

#### Format Money with Currency Symbol

[](#format-money-with-currency-symbol)

```
@moneyWithSymbol(10000, 'USD')
{{-- Output: $ 10,000.00 --}}

@moneyWithSymbol($price, 'EUR')
{{-- Output: € 1,234.56 --}}
```

#### Format Currency with Locale

[](#format-currency-with-locale)

```
@currency(10000, 'USD', 'en_US')
{{-- Output: $10,000.00 --}}

@currency($amount, 'EUR', 'de_DE')
{{-- Output: 10.000,00 € --}}
```

#### Convert Number to Words

[](#convert-number-to-words)

```
@numbertowords(10000)
{{-- Output: ten thousand --}}

@numbertowords(123456)
{{-- Output: one hundred twenty-three thousand four hundred fifty-six --}}
```

### Helper Functions

[](#helper-functions)

```
// Format money
$formatted = format_money(10000);
// Returns: "10,000.00"

// Convert to words
$words = money_to_words(1234);
// Returns: "one thousand two hundred thirty-four"

// Format as currency
$currency = format_currency(10000, 'USD', 'en_US');
// Returns: "$10,000.00"

// Parse formatted money back to float
$amount = parse_money('10,000.00');
// Returns: 10000.0
```

### Facade

[](#facade)

```
use Williamug\MoneyFormatter\Facades\Money;

// Basic formatting
Money::format(10000);
// Returns: "10,000.00"

// Format with currency symbol
Money::formatWithSymbol(10000, 'USD');
// Returns: "$ 10,000.00"

// Convert to words
Money::toWords(1234);
// Returns: "one thousand two hundred thirty-four"

// Format with locale
Money::formatCurrency(10000, 'EUR', 'de_DE');
// Returns: "10.000,00 €"

// Parse formatted string
Money::parse('1,234.56');
// Returns: 1234.56

// Chain methods for custom formatting
Money::setDecimals(0)->format(10000);
// Returns: "10,000"

Money::setCurrency('EUR')->formatWithSymbol(10000);
// Returns: "€ 10,000.00"
```

### Direct Class Usage

[](#direct-class-usage)

```
use Williamug\MoneyFormatter\MoneyFormatter;

$formatter = new MoneyFormatter();

// Format money
$result = $formatter->format(1234.56);
// Returns: "1,234.56"

// Customize formatting
$result = $formatter
    ->setDecimals(0)
    ->setCurrency('EUR')
    ->format(1234.56);
// Returns: "1,235"

// Format with symbol
$result = $formatter->formatWithSymbol(1234.56, 'USD');
// Returns: "$ 1,234.56"
```

Advanced Formatters
-------------------

[](#advanced-formatters)

### Percentage Formatting

[](#percentage-formatting)

```
// Facade
Money::percentage(50); // "50.00%"
Money::percentage(75.5, 1); // "75.5%"
Money::percentage(100, 0, false); // "100" (without % sign)

// Helper
format_percentage(50); // "50.00%"

// Blade
@percentage(50) {{-- 50.00% --}}
```

### File Size Formatting

[](#file-size-formatting)

```
// Facade
Money::fileSize(1024); // "1.00 KB"
Money::fileSize(1048576); // "1.00 MB"
Money::fileSize(1073741824); // "1.00 GB"

// Helper
format_filesize(1024); // "1.00 KB"

// Blade
@filesize(1024) {{-- 1.00 KB --}}
```

### Number Abbreviation

[](#number-abbreviation)

```
// Facade
Money::abbreviate(1000); // "1.0K"
Money::abbreviate(1500000); // "1.5M"
Money::abbreviate(1000000000); // "1.0B"

// Helper
abbreviate_number(1000000); // "1.0M"

// Blade
@abbreviate(1000000) {{-- 1.0M --}}
```

### Ordinal Numbers

[](#ordinal-numbers)

```
// Facade
Money::ordinal(1); // "1st"
Money::ordinal(2); // "2nd"
Money::ordinal(3); // "3rd"
Money::ordinal(21); // "21st"

// Helper
format_ordinal(1); // "1st"

// Blade
@ordinal(1) {{-- 1st --}}
```

### Phone Number Formatting

[](#phone-number-formatting)

```
// Facade
Money::phone('1234567890', 'international'); // "+1 (123) 456-7890"
Money::phone('1234567890', 'national'); // "(123) 456-7890"
Money::phone('1234567890', 'dots'); // "123.456.7890"

// Helper
format_phone('1234567890'); // "+1 (123) 456-7890"

// Blade
@phone('1234567890') {{-- +1 (123) 456-7890 --}}
```

### Credit Card Masking

[](#credit-card-masking)

```
// Facade
Money::creditCard('1234567890123456'); // "**** **** **** 3456"
Money::creditCard('1234567890123456', 'X', 4); // "XXXX XXXX XXXX 3456"

// Helper
format_creditcard('1234567890123456'); // "**** **** **** 3456"

// Blade
@creditcard('1234567890123456') {{-- **** **** **** 3456 --}}
```

### Duration Formatting

[](#duration-formatting)

```
// Facade
Money::duration(60); // "1 minute"
Money::duration(3600); // "1 hour"
Money::duration(86400); // "1 day"
Money::duration(90); // "1 minute, 30 seconds"
Money::duration(3665, true); // "1h, 1m" (short format)

// Helper
format_duration(3600); // "1 hour"

// Blade
@duration(3600) {{-- 1 hour --}}
```

### Additional Formatters

[](#additional-formatters)

```
// Metric notation (SI units)
Money::metric(1500, 2, 'W'); // "1.50kW"
Money::metric(1500000, 1, 'W'); // "1.5MW"

// Compact numbers (locale-aware)
Money::compact(1500000); // "1.5M"

// Decimal to fraction
Money::fraction(0.5); // "1/2"
Money::fraction(0.333, 100); // "1/3"

// Ordinal words
Money::ordinalWords(1); // "1st" (locale-dependent)
```

Configuration
-------------

[](#configuration)

The `config/money-formatter.php` file provides extensive customization:

```
return [
    // Default locale (e.g., 'en_US', 'de_DE')
    'default_locale' => 'en_US',

    // Default currency code
    'default_currency' => 'USD',

    // Number of decimal places
    'decimals' => 2,

    // Thousand separator
    'thousand_separator' => ',',

    // Decimal separator
    'decimal_separator' => '.',

    // Show currency symbol by default
    'show_symbol' => false,

    // Symbol position: 'before' or 'after'
    'symbol_position' => 'before',

    // Locale for number to words
    'words_locale' => 'en',

    // Currency symbols mapping
    'currency_symbols' => [
        'USD' => '$',
        'EUR' => '€',
        'GBP' => '£',
        'UGX' => 'UGX',
        // ... add more
    ],
];
```

Advanced Examples
-----------------

[](#advanced-examples)

### Multiple Currency Formatting in a View

[](#multiple-currency-formatting-in-a-view)

```

    Invoice #{{ $invoice->number }}

    Subtotal: @money($invoice->subtotal)
    Tax: @money($invoice->tax)
    Total: @moneyWithSymbol($invoice->total, 'USD')

        Amount in words: @numbertowords($invoice->total)

```

### Dynamic Currency Formatting

[](#dynamic-currency-formatting)

```
// In your controller
$currencies = ['USD', 'EUR', 'GBP'];
$amount = 1234.56;

foreach ($currencies as $currency) {
    $formatted = Money::formatWithSymbol($amount, $currency);
    echo "$currency: $formatted\n";
}
```

### Custom Precision

[](#custom-precision)

```
// Cryptocurrency with 8 decimals
$btc = Money::setDecimals(8)->format(0.00123456);
// Returns: "0.00123456"

// Whole numbers only
$quantity = Money::setDecimals(0)->format(1234.56);
// Returns: "1,235"
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Run tests with coverage:

```
composer test-coverage
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [williamug](https://github.com/Williamug)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~153 days

Recently: every ~218 days

Total

10

Last Release

90d ago

Major Versions

0.1.0 → 1.0.02022-05-10

1.2 → 2.02023-09-30

2.0.1 → 3.0.02025-12-01

PHP version history (2 changes)0.1.0PHP ^8.1

3.0.0PHP ^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/a574762c42c4aac532a36603bcd5942930718bbaaeff1f59bbaed2a962b79588?d=identicon)[williamug](/maintainers/williamug)

---

Top Contributors

[![Williamug](https://avatars.githubusercontent.com/u/15543507?v=4)](https://github.com/Williamug "Williamug (111 commits)")

---

Tags

formatterlaravelpercentagedurationcredit-cardblade-directivesfile-sizenumber-abbreviationphone-formattermoney-formatterordinal-numbers

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/williamug-money-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/williamug-money-formatter/health.svg)](https://phpackages.com/packages/williamug-money-formatter)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
