abdulbaset/convert-numbers
Composer 安装命令:
composer require abdulbaset/convert-numbers
包简介
A PHP package to convert numbers to words and currencies in multiple languages
关键字:
README 文档
README
Convert Numbers
A comprehensive PHP package for number conversion, supporting multiple languages and various conversion types.
Installation
Install the package via Composer:
composer require abdulbaset/convert-numbers
Usage
Basic Number Conversion
use Abdulbaset\ConvertNumbers\ConvertNumbers; // English (default) echo ConvertNumbers::toWords(42); // "forty-two" echo ConvertNumbers::toWords(1234.56); // "one thousand two hundred thirty-four point five six" // Arabic echo ConvertNumbers::toWords(42, 'ar'); // "اثنان و أربعون" echo ConvertNumbers::toWords(1234.56, 'ar'); // "ألف و مائتان و أربعة و ثلاثون فاصلة خمسة ستة" // French echo ConvertNumbers::toWords(42, 'fr'); // "quarante-deux"
Currency Conversion
// Basic currency to words echo ConvertNumbers::currencyToWords(1234.56, 'USD'); // "one thousand two hundred thirty-four dollars and fifty-six cents only" // Arabic currency echo ConvertNumbers::currencyToWords(1234.56, 'EGP', 'ar'); // "ألف و مائتان و أربعة و ثلاثون جنيه مصري و ستة و خمسون قرش فقط لا غير" // Currency formatting echo ConvertNumbers::currencyFormat(1234567.89, 'USD', 'en', true); // "1,234,567.89 $" echo ConvertNumbers::currencyFormat(1234567.89, 'EGP', 'ar', true); // "١٬٢٣٤٬٥٦٧٫٨٩ ج.م"
File Size Formatting
// Basic file size formatting echo ConvertNumbers::toFileSize(1024); // "1.00 KB" echo ConvertNumbers::toFileSize(1024 * 1024); // "1.00 MB" // Arabic formatting echo ConvertNumbers::toFileSize(1024, 'ar'); // "١٫٠٠ كيلوبايت" echo ConvertNumbers::toFileSize(1024 * 1024, 'ar'); // "١٫٠٠ ميجابايت" // French formatting echo ConvertNumbers::toFileSize(1024, 'fr'); // "1,00 Ko" echo ConvertNumbers::toFileSize(1024 * 1024, 'fr'); // "1,00 Mo" // Custom decimal places echo ConvertNumbers::toFileSize(1234567, 'en', 3); // "1.177 MB"
Architecture
The package follows SOLID principles and clean architecture:
-
Single Responsibility Principle (SRP)
- Each class has a single responsibility
- Language classes handle language-specific conversions
- Currency classes manage currency-specific logic
- Utility classes for formatting and conversion
-
Open/Closed Principle (OCP)
- Easy to add new languages by extending
LanguageAbstract - New currencies can be added by extending
CurrencyAbstract - No modification needed to existing code
- Easy to add new languages by extending
-
Interface Segregation Principle (ISP)
- Separate interfaces for different functionalities
ConverterInterfacefor number conversionCurrencyInterfacefor currency operationsFileSizeInterfacefor file size formatting
-
Dependency Inversion Principle (DIP)
- High-level modules depend on abstractions
- Easy to swap implementations
Features
1. Number to Words Conversion
- Convert integers and decimal numbers to words
- Support for negative numbers
- Decimal point handling
- Language-specific formatting
2. Currency Handling
- Convert currency amounts to words
- Format currency with proper separators
- Optional currency symbol display
- Support for multiple currencies:
- USD (US Dollar)
- EUR (Euro)
- EGP (Egyptian Pound)
- SAR (Saudi Riyal)
3. File Size Formatting
- Convert bytes to human-readable formats
- Automatic unit selection (B, KB, MB, GB, TB, PB)
- Language-specific unit names
- Customizable decimal places
4. Multi-language Support
- Arabic (ar)
- English (en)
- French (fr)
5. Number Formatting
- Language-specific decimal separators
- Thousands separators
- Arabic numeral conversion
Use Cases
Here are some practical scenarios where this package can be useful:
📄 Invoices & Legal Documents
- Convert numbers to words in invoices and contracts for better clarity.
- Display financial amounts in words to ensure legal accuracy.
💰 Financial & Accounting Applications
- Format and display monetary values properly.
- Convert currency values into readable words for multi-language support.
🛍 CMS & E-commerce Platforms
- Improve user experience by displaying formatted numbers in different languages.
- Show file sizes in a human-readable format for media uploads.
🌍 Multi-language Applications
- Convert numeric values to words in different languages without extra dependencies.
- Provide better localization for global users.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
Change Log
For a detailed list of changes and updates in each version, see the Change Log.
License
This package is open-sourced software licensed under the LICENSE license.
Support
For support:
- Email: AbdulbasetRedaSayedHF@Gmail.com
- Create an issue in the GitHub repository
Donations 💖
Maintaining this package takes time and effort. If you’d like to support its development and keep it growing, you can:
- 🌟 Star this repository
- 📢 Sharing it with others
- 🛠️ Contribute by reporting issues or suggesting features
- ☕ Buy me a coffee
- ❤️ Become a sponsor on GitHub Sponsors
- 💵 Make a one-time donation via PayPal
Your support means a lot to me! Thank you for making this possible. 🙏
abdulbaset/convert-numbers 适用场景与选型建议
abdulbaset/convert-numbers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「currency converter」 「PHP Library」 「multi-language」 「number conversion」 「number-to-words」 「arabic numbers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 abdulbaset/convert-numbers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abdulbaset/convert-numbers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 abdulbaset/convert-numbers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Encode integer IDs using a preset or customized symbol set
Fixer.io data provider for Peso
TCMB Currenct Converter
Immutable PHP currency converter that's data-agnostic.
Alfabank REST API integration
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-29