๐Ÿš€ Usage - Customization

The Laravel Currency Formatter package offers flexible ways to customize currency formatting to fit your needs. Whether you need to change the currency symbol, adjust the decimal places, or specify the symbol positioning, this package has you covered.

Table of Contents

Changing the Currency Symbol

To change the currency symbol for your formatting, you can use the setSymbol method provided by the Currency class. This allows you to specify a custom symbol for the currency.

use Magarrent\LaravelCurrencyFormatter;

$currencyFormatter = new Currency();

// Set your desired currency
$currencyFormatter->currency('USD');

// Customize the symbol
$currencyFormatter->setSymbol('ยค'); // Use your desired symbol here

// Format a given number
echo $currencyFormatter->format(1234.56);

This will output the formatted currency string with your custom symbol.

Adjusting Decimal Places

The number of decimal places is determined by the selected currency's configuration found in src/resources/Currencies.php. However, you can directly influence the output's decimal places by passing a boolean flag as the second argument to the format method. Setting this flag to true will format the number with zero decimal places.

// Format number with zero decimal places
echo $currencyFormatter->format(1234.56, true); // Outputs with zero decimal places

Note: This override only allows for zero decimal places. For a different number of decimal places, consider other customization options or manipulating the output string directly.

Symbol Positioning

Symbol positioning (whether the symbol appears on the left or the right of the amount) and whether there is a space between the amount and the symbol are predefined by the currency settings in src/resources/Currencies.php. While there isn't a direct method to change this behavior dynamically, you could adjust these settings directly in the configuration file for your currency of interest, or manipulate the format string returned by the format method.


This customization documentation aims to empower developers using the Laravel Currency Formatter package to tailor their currency display to precisely match their application needs. For further customization, consider reviewing the src/resources/Currencies.php for configurations available per currency or extending the Currency class for even more flexibility.