Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Krishma's avatar

How to convert number into words in DomPDF using laravel??

I am using Barryvdh Dompdf

0 likes
4 replies
Krishma's avatar

@ahkeravi Suppose i have 9076.63 then in words i want Ninety Thousand Seventy six cents sixty three

ahkeravi's avatar

@krishma https://github.com/patrickschur/number-to-words

use NumberToWords\NumberToWords;
use NumberToWords\Locale\English;
 
$c = new NumberToWords(new English()); // english
 
// One followed by 3003 zeros
echo $c->nameOfLargeNumber(3003); // outputs "millinillion"
 
echo $n->convert('3043.43'); // outputs "three thousand forty-three point four three"
echo $n->convert('3.1415926535'); // outputs "three point one four one five nine two six five three five"

Sti3bas's avatar
use NumberToWords\NumberToWords;

function amountInWords($total, $lang = 'en', $currency = 'USD')
{
    return (new NumberToWords())
        ->getCurrencyTransformer($lang)
        ->toWords((int)($total * 100), $currency);
}

dd(amountInWords(9076)); // nine thousand seventy-six dollars
dd(amountInWords(9076.95)); // nine thousand seventy-six dollars ninety-five cents
dd(amountInWords(9076.95, 'fr', 'EUR')); // neuf mille soixante-seize euros et quatre-vingt-quinze centimes

https://github.com/kwn/number-to-words

1 like

Please or to participate in this conversation.