PHP code example of gerardojbaez / money

1. Go to this page and download the library: Download gerardojbaez/money 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/ */

    

gerardojbaez / money example snippets




$money = new Gerardojbaez\Money\Money(12.99, 'USD')
$money->format(); // RESULT: $12.99

// You can also use the 



erardojbaez\Money\Money;

$money = new Money(100);
$money->format();



// USD
echo moneyFormat(100); // RESULT: $100.00
echo moneyFormat(10000); // RESULT: $10,000.00

// INR
echo moneyFormat(100, 'INR'); // RESULT: र100
echo moneyFormat(1000000, 'INR'); // RESULT: र10,00,000



$money = new Gerardojbaez\Money\Money(1000000, 'INR');

echo $money->format(); // RESULT: र10,00,000
echo $money; // The same as using $money->format()

echo $money->amount(); // RESULT: 10,00,000

$currency = new Gerardojbaez\Money\Currency('USD');
$currency->setPrecision(3);
$currency->setThousandSeparator('.');
$currency->setDecimalSeparator(',');
$currency->setSymbolPlacement('after');

$money = new Gerardojbaez\Money\Money(1200.9, $currency);
echo $money; // RESULT: 1.200,900$ (example)

// OR
echo moneyFormat(1200.9, $currency);



echo Money::parse('$1,200.90', 'USD')->toDecimal(); // RESULT: 1200.9


$currency = new Gerardojbaez\Money\Currency('USD');
echo $currency->getTitle(); // US Dollar
echo $currency->getCode(); // USD
echo $currency->getSymbol(); // $
echo $currency->getSymbolPlacement(); // after (before|after amount)
echo $currency->getPrecision(); // 2 (number of decimals)
echo $currency->getThousandSeparator(); // ,
echo $currency->getDecimalSeparator(); // .


$currencies = Gerardojbaez\Money\Currency::getAllCurrencies();

// Result Example:
[
	'ARS' => [
		'code' => 'ARS'
		'title' => 'Argentine Peso'
		'symbol' => null
		'precision' => 2
		'thousandSeparator' => ','
		'decimalSeparator' => '.'
		'symbolPlacement' => 'before'
	]

	'AMD' => [
		'code' => 'AMD'
		'title' => 'Armenian Dram'
		'symbol' => null
		'precision' => 2
		'thousandSeparator' => '.'
		'decimalSeparator' => ','
		'symbolPlacement' => 'before'
	]

	...