PHP code example of bobbydum / number-to-words

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

    

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

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"

$options = new CurrencyTransformerOptions();
$options->setShowFractionIfZero(true);
$options->setConvertFraction(false);
$currencyTransformer->toWords(5000,Language::getCurrentCurrency(),$options); // outputs "fifty dollars 00 cents"