PHP code example of abdulbaset / convert-numbers

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

    

abdulbaset / convert-numbers example snippets


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"

// 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); // "١٬٢٣٤٬٥٦٧٫٨٩ ج.م"

// 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"