Download the PHP package laxmidhar/desi-currency without Composer
On this page you can find all versions of the php package laxmidhar/desi-currency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laxmidhar/desi-currency
More information about laxmidhar/desi-currency
Files in laxmidhar/desi-currency
Package desi-currency
Short Description A little toolkit that teaches Laravel to count in rupees โ because not every app runs on dollars.
License MIT
Homepage https://github.com/dante-san/desi-currency
Informations about the package desi-currency
Desi Currency - Indian Currency Helper for Laravel
A comprehensive Laravel package for handling Indian currency formatting, conversions, and utilities. Format amounts in Lakhs, Crores, convert to words, parse shorthand notations (1L, 2.5Cr), and much more - all following Indian numbering standards.
โจ Features
- ๐ฎ๐ณ Indian Numbering System - Proper comma placement (โน1,23,456.78)
- ๐ฐ Lakh & Crore Formatting - Convert to Lakhs, Crores with ease
- ๐ค Words Conversion - Amount to Indian words (One Lakh Twenty Three Thousand)
- ๐ Shorthand Support - Parse and format 1L, 2.5Cr, 500K notations
- ๐ Two-way Conversion - Format to shorthand and parse back to numbers
- โ Zero Configuration - Works out of the box
- ๐ฏ Production Ready - Fully tested and optimized
- ๐ฆ Auto-Discovery - Automatically registers with Laravel
๐ Requirements
- PHP 8.0 or higher
- Laravel 9.x, 10.x, 11.x, or 12.x
๐ Installation
Install via Composer:
The service provider will be automatically registered via Laravel's package auto-discovery.
๐ Usage
Facade Usage (Recommended)
Direct Class Usage
Dependency Injection
๐งฉ Available Methods
๐ฐ Core Formatting Methods
format(float $amount, bool $showSymbol = true): string
Format amount using Indian numbering system (โน1,23,456.78).
Parameters:
$amount- Amount to format$showSymbol- Whether to include โน symbol (default: true)
Examples:
Key Features:
- Follows Indian comma placement (last 3 digits, then groups of 2)
- Handles negative amounts
- Always shows 2 decimal places
- Optional currency symbol
formatWhole(float $amount, bool $showSymbol = true): string
Format amount without decimal places.
Parameters:
$amount- Amount to format$showSymbol- Whether to include โน symbol (default: true)
Examples:
Use Cases:
- Display whole rupees only
- Invoice totals
- Round number displays
- Reports and summaries
formatAccounting(float $amount, bool $showSymbol = true): string
Format for accounting purposes (negative values in parentheses).
Parameters:
$amount- Amount to format$showSymbol- Whether to include โน symbol (default: true)
Examples:
Use Cases:
- Financial statements
- Balance sheets
- Profit/Loss reports
- Accounting software
๐ค Words & Shorthand Conversion
toWords(float $amount, bool $showSymbol = true): string
Convert amount to readable words format (Lakh, Crore, K).
Parameters:
$amount- Amount to convert$showSymbol- Whether to include โน symbol (default: true)
Examples:
Conversion Logic:
- โฅ 1 Crore (10,000,000): Shows in Crores
- โฅ 1 Lakh (100,000): Shows in Lakhs
- โฅ 1 Thousand (1,000): Shows with K suffix
- < 1 Thousand: Shows as is
toShorthand(float $amount, bool $showSymbol = true): string
Convert to compact shorthand notation (1L, 2.5Cr, 500K).
Parameters:
$amount- Amount to convert$showSymbol- Whether to include โน symbol (default: true)
Examples:
Use Cases:
- Dashboard widgets
- Mobile app displays
- Quick summaries
- Data tables
- Charts and graphs
toLakhs(float $amount, int $decimals = 2, bool $showSymbol = true): string
Always format in Lakhs, regardless of amount.
Parameters:
$amount- Amount to convert$decimals- Number of decimal places (default: 2)$showSymbol- Whether to include โน symbol (default: true)
Examples:
Use Cases:
- Real estate pricing
- Salary negotiations
- Project budgets
- Property valuations
toCrores(float $amount, int $decimals = 2, bool $showSymbol = true): string
Always format in Crores, regardless of amount.
Parameters:
$amount- Amount to convert$decimals- Number of decimal places (default: 2)$showSymbol- Whether to include โน symbol (default: true)
Examples:
Use Cases:
- Company valuations
- Large transactions
- Annual reports
- Government budgets
- Infrastructure projects
toIndianWords(float $amount): string
Convert amount to complete Indian words format.
Parameters:
$amount- Amount to convert
Examples:
Use Cases:
- Cheque printing
- Invoice generation
- Legal documents
- Payment receipts
- Bank transactions
๐ Parsing & Conversion
parse(string $amount): float
Parse Indian currency notation back to numeric value.
Parameters:
$amount- String amount to parse
Examples:
Supported Formats:
- Shorthand: 1L, 2.5Cr, 500K
- Words: 1 Lakh, 2.5 Crore
- With symbols: โน1L, Rs 2Cr
- With commas: 1,50,000
- Negative values: -1.5L
Use Cases:
- User input parsing
- Import data processing
- API integrations
- Form submissions
๐ง Utility Methods
symbol(): string
Get the rupee currency symbol.
Examples:
splitRupeesPaise(float $amount): array
Split amount into rupees and paise components.
Parameters:
$amount- Amount to split
Examples:
Use Cases:
- Cheque printing
- Detailed invoices
- Payment breakdowns
- Accounting entries
formatWithSuffix(float $amount, string $suffix = '', bool $showSymbol = true): string
Format amount with custom suffix.
Parameters:
$amount- Amount to format$suffix- Custom suffix text$showSymbol- Whether to include โน symbol (default: true)
Examples:
Use Cases:
- Subscription pricing
- Product pricing
- EMI displays
- Offer pricing
isLakhsRange(float $amount): bool
Check if amount is in the Lakhs range (1L to 1Cr).
Parameters:
$amount- Amount to check
Examples:
Use Cases:
- Conditional formatting
- Range-based displays
- Report categorization
isCroresRange(float $amount): bool
Check if amount is in the Crores range (โฅ1Cr).
Parameters:
$amount- Amount to check
Examples:
Use Cases:
- Large transaction handling
- Report filtering
- Display logic
๐ก Practical Examples
E-commerce Product Display
Invoice Generation
Dashboard Statistics
Salary Package Display
User Input Processing
Financial Reports
Real Estate Listings
Blade Templates
๐จ Blade Directives
Desi Currency provides convenient Blade directives for use in your Laravel views, making currency formatting clean and readable.
Quick Reference Table
| Directive | Purpose | Input Example | Output Example |
|---|---|---|---|
@currency($amount) |
Standard format with symbol | 123456.78 |
โน1,23,456.78 |
@currencyWhole($amount) |
Format without decimals | 123456.78 |
โน1,23,457 |
@currencyPlain($amount) |
Format without symbol | 123456.78 |
1,23,456.78 |
@currencyAccounting($amount) |
Accounting format | -5000 |
(โน5,000.00) |
@inLakhs($amount) |
Always show in Lakhs | 1500000 |
โน15.00 Lakhs |
@inCrores($amount) |
Always show in Crores | 15000000 |
โน1.50 Crores |
@currencyShort($amount) |
Compact notation | 1500000 |
โน15L |
@currencyWords($amount) |
Readable format | 1500000 |
โน15 Lakh |
@currencySpell($amount) |
Full words | 123456 |
One Lakh Twenty Three Thousand... |
@rupeeSymbol |
Rupee symbol only | - | โน |
@inLakhRange($amount) |
Check Lakh range | 500000 |
true/false |
@inCroreRange($amount) |
Check Crore range | 15000000 |
true/false |
Available Directives
Standard Formatting
@currency($amount) - Format with Indian numbering and โน symbol
@currencyWhole($amount) - Format without decimals
@currencyPlain($amount) - Format without currency symbol
@currencyAccounting($amount) - Accounting format (negatives in parentheses)
Indian Units (Lakh & Crore)
@inLakhs($amount) - Always display in Lakhs
@inCrores($amount) - Always display in Crores
Shorthand & Words
@currencyShort($amount) - Compact notation (L, Cr, K)
@currencyWords($amount) - Readable format (Lakh, Crore)
@currencySpell($amount) - Complete Indian words
Utilities
@rupeeSymbol - Just the rupee symbol
Conditional Directives
Use these to conditionally render based on amount range:
@inLakhRange($amount) - Check if amount is in Lakh range (1L - 1Cr)
@inCroreRange($amount) - Check if amount is in Crore range (โฅ1Cr)
Practical Blade Examples
Product Card
Invoice Template
Dashboard Widget
Financial Report
Salary Package Display
๐ฏ Best Practices
1. Consistent Display
Use the same format throughout your application for consistency:
2. Store as Numeric, Display as Formatted
Always store amounts as numeric values in database:
3. Handle User Input Properly
Parse user input before storing:
4. Use Appropriate Format for Context
Choose format based on where it's displayed:
5. Handle Negative Amounts
Always check for negative values:
๐งช Testing
Run the test suite:
Run tests with coverage:
Example Test Cases
๐ Comparison with Other Solutions
| Feature | Desi Currency | Manual Formatting | Other Packages |
|---|---|---|---|
| Indian Numbering | โ | โ | โ ๏ธ Limited |
| Lakh/Crore Support | โ | โ | โ |
| Shorthand Parsing | โ | โ | โ |
| Words Conversion | โ | โ | โ ๏ธ English only |
| Zero Config | โ | N/A | โ |
| Laravel Integration | โ | N/A | โ ๏ธ Limited |
๐ Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
๐ค Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure:
- All tests pass
- Code follows PSR-12 standards
- New features include tests
- Documentation is updated
๐ Changelog
Please see CHANGELOG for recent changes.
๐ License
This package is open-sourced software licensed under the MIT license.
๐จโ๐ป Author
Laxmidhar Maharana
Senior Laravel Developer โข Open Source Contributor
โญ Show Your Support
If this package helped you, please give it a โญ๏ธ on GitHub!
๐ Acknowledgments
Special thanks to:
- The Laravel community for inspiration
- Indian developers who understand the pain of currency formatting
๐ Related Packages
- Laravel Helpers - 85+ Helper Functions
- Laravel Money - Money handling
- Laravel Cashier - Subscription billing
๐บ๏ธ Roadmap
โ Completed
- [x] Blade directives for formatting
๐ Upcoming
- [ ] Add support for other Indian regional formats
- [ ] Currency conversion support
- [ ] GST calculations
- [ ] Tax computation helpers
- [ ] Multi-currency support
โ FAQ
Q: Can I use this for non-Indian currencies?
A: This package is specifically designed for Indian Rupee and Indian numbering system. For other currencies, consider using Laravel Money or similar packages.
Q: Does it handle GST calculations?
A: Not yet, but it's on the roadmap. Current version focuses on formatting and conversion.
Q: Can I customize the decimal places?
A: Yes, methods like toLakhs() and toCrores() accept a $decimals parameter.
Q: Does it work with Blade templates?
A: Yes! You can use the Currency facade directly in Blade templates as shown in the examples above.
Q: How do I handle very large amounts (Thousands of Crores)?
A: The package handles amounts up to PHP's float limit. For extremely large numbers, consider using BC Math functions.
Made with โค๏ธ for Indian Developers
Supporting Digital India โข Made in India ๐ฎ๐ณ