Search
How to Convert Any Number into Word in Laravel - WebJourney

How to Convert Any Number into Word in Laravel - WebJourney

Hello, friends! In this tutorial, I will teach you how to convert any number into words using Laravel. Whether it's 10, 290, 23,897, or 2,000,220—no matter the size—we can achieve this with a single line of code. Let's dive into a real example to see how to convert any number to words easily.

Step-1: Install laravel

To instal laravel run the below command. If you have already a project you can start with this.

composer create-project --prefer-dist laravel/laravel number-to-word

Step-2: Instal terbilang package

To convert number into words we need to install the terbilang package using the below command.

composer require riskihajar/terbilang:^2.0

Step-3: Add Providers & Aliases

In the $providers array add the service providers for this package.

config/app.php

Riskihajar\Terbilang\TerbilangServiceProvider::class,
  'providers' => ServiceProvider::defaultProviders()->merge([
        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
        Riskihajar\Terbilang\TerbilangServiceProvider::class,
    ])->toArray(),

Add the facade of this package to the $aliases array.

config/app.php

'Terbilang' => Riskihajar\Terbilang\Facades\Terbilang::class,
'aliases' => Facade::defaultAliases()->merge([
        // 'Example' => App\Facades\Example::class,
        'Terbilang' => Riskihajar\Terbilang\Facades\Terbilang::class,
    ])->toArray(),

Our setup is complete. Now let's see how to use it. It's very simple. Just add oneline code in your blade file to convert any number into word.

Usage: Just call the make method from terbilang and put your number or variable to convert into word.

welcome.blade.php

 <p>{{ Terbilang::make(1000) }}</p>  //output: one thousand
 <p>{{ Terbilang::make(2343) }}</p>  //output: two thousand three hundred forty-three    
 <p> {{ Terbilang::make(5098373) }}</p>  //output: five million ninety-eight thousand three hundred seventy-three

 

Video Link:  Click to View on Video Tutorial

This package has lot's of feature. you can check it for more details.

https://github.com/riskihajar/terbilang

🎯 Interactive Skill Assessment
Laravel Challenge: How Well Do You Know the PHP Framework Devs Love?

Test what you just learned with 31 interactive multiple-choice questions and instant explanations.

Start Free Quiz

Tags

Share This:

NH
Written by Nazmul Hoque • Senior Full-Stack Developer (8+ Years Experience)

Senior Full-Stack Engineer with 8+ years of experience building production web and mobile applications using Laravel, Next.js, TypeScript, JavaScript, React, Vue.js, MySQL, PostgreSQL, and Flutter.

You May Also Like Below Articles

Handpicked related tutorials and step-by-step developer guides to continue learning.