msajko / money-formatter
Money to text converter
v0.1-alpha
2017-07-10 08:57 UTC
Requires
- php: >=5.4
- ext-intl: >=1.0
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2025-07-12 01:00:20 UTC
README
Supported money formats:
- set amount
- country_code formats
setAmount(amount, country_code)
- {us,gb,au,..}
12,432.23
$12,432.23
£12,432.23
EUR 12,432.23
... - {de,at,es,..}
12.432,23
12 432,23
12 432,23 EUR
12.432,23 €
... - {fr}
12 432,23
12 432,23 EUR
12 432,23 €
- {ch}
12'432.23
fr. 12'432.23
- {dz,eg,iq,sa}
12,432.23
12,432.232 ج.م.
12,432.232 ج.م.
- croatian money format e.q.
12.432,23
or12.432,23 Kn
- others ...
- {us,gb,au,..}
- integer, double
setAmountDirect()
- country_code formats
- get pronunciation
get(money, penny, separator)
- {en}
get('£', 'pence',' and')
->twelve thousand four hundred thirty-two £ and twenty-three pence
- {de}
get('€', 'Cent', ' und')
->zwölftausendvierhundertzweiunddreißig € und dreiundzwanzig Cent
- {it}
get('€', '¢', ' e')
->dodicimilaquattrocentotrentadue € e ventitré ¢
- {hr}
getHr('€', 'centa', ' i')
[intl independent] ->dvanaesttisućačetiristotridesetidvije kune i dvadesetitri lipe
- others ...
- {en}
How to use
composer require msajko/money-formatter
or
git clone https://github.com/msajko/money-formatter
create index.php
:
<?php use Msajko\MoneySpellOut; //if you not using composer include_once('src/money-formatter.php'); //$amount=(rand(1, 9999).','.str_pad( rand(0, 99),2,'0',STR_PAD_LEFT)); $amount='12.432,23'; $money = new MoneySpellOut('de', $amount); echo 'DE: "'.$amount.'" => '.$money->get('€', '¢',' und').PHP_EOL; $amount='12.432,23 €'; $money->setAmount($amount, 'it'); $money->setCountrycode('it'); echo 'IT: "'.$amount.'" => '.$money->get('€', '¢',' e').PHP_EOL; $amount='12 432,23 €'; $money->setCountrycode('fr'); $money->setAmount($amount, 'fr'); echo 'FR: "'.$amount.'" => '.$money->get('€', '¢',' et').PHP_EOL; $amount='12.432,23 EUR'; $money->setCountrycode('es'); $money->setAmount($amount, 'es'); echo 'ES: "'.$amount.'" => '.$money->get('€', '¢',' y').PHP_EOL; $amount='€12,432.23'; $money->setCountrycode('gb'); $money->setAmount($amount, 'gb'); echo 'GB: "'.$amount.'" => '.$money->get('£', 'pence',' and').PHP_EOL; $amount='$12,432.23'; $money->setCountrycode('us'); $money->setAmount($amount, 'us'); echo 'US: "'.$amount.'" => '.$money->get('$', '¢',' &').PHP_EOL; echo PHP_EOL; $money->setCountrycode('hr'); echo 'HR(1): "'.$amount.'" => '.$money->get('kuna', 'lipa', ' i').PHP_EOL; //no spacing & php_intl independent echo 'HR(2): "'.$amount.'" => '.$money->getHr().PHP_EOL;
and run php index.php
You can try not to use this repository
enable intl php_extension and try:
$amount=12432; $nFormat = new NumberFormatter('de', NumberFormatter::SPELLOUT); $nFormat->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%spellout-ordinal-feminine"); var_dump($nFormat->format($amount));
inspired by
- http://trigeminal.fmsinc.com/samples/setlocalesample2.asp
- yii2 framework implementation Formatter::asSpellout()
plan to integrate