1. Go to this page and download the library: Download laxmidhar/desi-currency 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/ */
laxmidhar / desi-currency example snippets
use Laxmidhar\DesiCurrency\Facades\Currency;
// Format in Indian style
Currency::format(123456.78);
// Output: "₹1,23,456.78"
// Convert to words
Currency::toWords(150000);
// Output: "₹1.5 Lakh"
// Shorthand notation
Currency::toShorthand(2500000);
// Output: "₹25L"
// Parse back to number
Currency::parse('1.5L');
// Output: 150000
use Laxmidhar\DesiCurrency\Support\CurrencyService;
CurrencyService::format(123456.78);
CurrencyService::toWords(150000);
CurrencyService::toShorthand(2500000);
use Laxmidhar\DesiCurrency\Support\CurrencyService;
class InvoiceController extends Controller
{
public function __construct(protected CurrencyService $currency) {}
public function show($id)
{
$invoice = Invoice::find($id);
$formatted = $this->currency->format($invoice->total);
$inWords = $this->currency->toIndianWords($invoice->total);
return view('invoice.show', compact('invoice', 'formatted', 'inWords'));
}
}
use Laxmidhar\DesiCurrency\Facades\Currency;
$salary = 1800000; // 18 Lakhs per annum
// Annual
echo Currency::toLakhs($salary) . ' per annum';
// Output: "₹18.00 Lakhs per annum"
// Monthly
$monthly = $salary / 12;
echo Currency::format($monthly) . ' per month';
// Output: "₹1,50,000.00 per month"
use Laxmidhar\DesiCurrency\Facades\Currency;
// User enters "2.5L" in a form
$userInput = request('budget'); // "2.5L"
// Parse to numeric value
$numericValue = Currency::parse($userInput);
// Output: 250000
// Store in database
$property->budget = $numericValue;
$property->save();
// Display back to user
echo Currency::toWords($property->budget);
// Output: "₹2.5 Lakh"
// Dashboards: Shorthand
echo Currency::toShorthand($revenue);
// Reports: Full format
echo Currency::format($revenue);
// Invoices: Words
echo Currency::toIndianWords($total);
// Cards: Words format
echo Currency::toWords($amount);
$balance = -5000;
// Use accounting format for negatives
echo Currency::formatAccounting($balance);
// Output: "(₹5,000.00)"
use Laxmidhar\DesiCurrency\Facades\Currency;
test('formats amount in Indian style', function () {
expect(Currency::format(123456.78))
->toBe('₹1,23,456.78');
});
test('converts to lakhs notation', function () {
expect(Currency::toWords(150000))
->toBe('₹1.5 Lakh');
});
test('parses shorthand notation', function () {
expect(Currency::parse('1.5L'))
->toBe(150000.0);
});
test('converts to Indian words', function () {
expect(Currency::toIndianWords(1234.50))
->toBe('One Thousand Two Hundred Thirty Four Rupees and Fifty Paise');
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.