PHP code example of codemarkt / laravel-number-to-words

1. Go to this page and download the library: Download codemarkt/laravel-number-to-words 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/ */

    

codemarkt / laravel-number-to-words example snippets


return [
    'locale' => 'tr',
    'fallback_locale' => 'en',
    'case' => 'lowercase',
    'separator' => ' ',
];

// Convert numbers to words
number_to_words(154); // Uses default locale from config
number_to_words(154, 'tr'); // "yüz elli dört"
number_to_words(154, 'en'); // "one hundred fifty four"

// Convert currency amounts
number_to_currency_words(8097.21, 'TRY', 'tr'); // "sekiz bin doksan yedi türk lirası yirmi bir kuruş"
number_to_currency_words(150.50, 'USD', 'en'); // "one hundred fifty us dollar fifty cent"

// With custom formatting
number_to_words(123, 'tr', 'uppercase', '-'); // "YÜZ-YİRMİ-ÜÇ"

use CodeMarkt\NumberToWords\Facades\NumberToWords;

// Or use the global alias (automatically registered)
use NumberToWords;

NumberToWords::toWords(154, 'tr'); // "yüz elli dört"
NumberToWords::toCurrency(8097.21, 'TRY', 'tr'); // "sekiz bin doksan yedi türk lirası yirmi bir kuruş"

$service = app(\CodeMarkt\NumberToWords\NumberToWordsService::class);
$service->toWords(154, 'tr');

NumberToWords::toWords('8.097,21'); // Turkish format → 8097.21
NumberToWords::toWords('1,200.56'); // English format → 1200.56
NumberToWords::toWords('18 500,90'); // With spaces → 18500.90
NumberToWords::toWords(1200.0); // Float
NumberToWords::toWords(1200); // Integer

'currencies' => [
    'JPY' => [
        'major' => 'Japanese yen',
        'minor' => '', // Leave empty if no minor unit
    ],
],

'currencies' => [
    'USD' => [
        'major' => [
            'singular' => 'US dollar',
            'plural' => 'US dollars',
        ],
        'minor' => [
            'singular' => 'cent',
            'plural' => 'cents',
        ],
    ],
],

return [
    'digits' => [
        '0' => 'zero',
        '1' => 'one',
        // ...
    ],
    'tens' => [
        '10' => 'ten',
        '20' => 'twenty',
        // ...
    ],
    'hundred' => 'hundred',
    'exponents' => [
        0 => '',
        1 => 'thousand',
        2 => 'million',
        // ...
    ],
    'currencies' => [
        'USD' => [
            'major' => 'dollar',
            'minor' => 'cent',
        ],
        // ...
    ],
];