PHP code example of compono-kit / money-formatters

1. Go to this page and download the library: Download compono-kit/money-formatters library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

compono-kit / money-formatters example snippets


interface FormatsMoneyString
{
    public function formatString(RepresentsMoney $money): string;
}

$formatter = new SimpleMoneyFormatter(CurrencyOutput::RIGHT_SYMBOL);

echo $formatter->formatString($money);
// Example: 1234.56 €

$formatter = new LocalizedDecimalMoneyFormatter('de_DE', CurrencyOutput::LEFT_SYMBOL);

echo $formatter->formatString($money);
// Example (German locale, left symbol): € 1.234,56

$formatter = new LocalizedMoneyFormatter('en_US');

echo $formatter->formatString($money);
// Example: $1,234.56

CurrencyOutput::LEFT_SYMBOL // e.g. € 1.234,56
CurrencyOutput::RIGHT_SYMBOL // e.g. 1.234,56 €
CurrencyOutput::LEFT_ISO_CODE  // e.g. EUR 1.234,56
CurrencyOutput::RIGHT_ISO_CODE   // e.g.  1.234,56 EUR
CurrencyOutput::NONE   // e.g. 1.234,56