PHP code example of kwn / number-to-words

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

    

kwn / number-to-words example snippets


use NumberToWords\NumberToWords;

// create the number to words "manager" class
$numberToWords = new NumberToWords();

// build a new number transformer using the RFC 3066 language identifier
$numberTransformer = $numberToWords->getNumberTransformer('en');

$numberTransformer->toWords(5120); // outputs "five thousand one hundred twenty"

NumberToWords::transformNumber('en', 5120); // outputs "five thousand one hundred twenty"

use NumberToWords\NumberToWords;

// create the number to words "manager" class
$numberToWords = new NumberToWords();

// build a new currency transformer using the RFC 3066 language identifier
$currencyTransformer = $numberToWords->getCurrencyTransformer('en');

$currencyTransformer->toWords(5099, 'USD'); // outputs "fifty dollars ninety nine cents"

NumberToWords::transformCurrency('en', 5099, 'USD'); // outputs "fifty dollars ninety nine cents"