How to Convert Any Number into Word in Laravel - WebJourney

How to Convert Any Number into Word in Laravel - WebJourney

  

How to Convert Any Number to Words in PHP: A Simple Guide

 

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

 

 

 

You May Also Like Bellow Articles:

 

 

Laravel live search data in a table using ajax. 

 

How to send SMS in laravel using Twilio SMS API-Webjourney

 

Laravel pdf invoice generate and download with barryvdh dompdf

 

How to create multi language website by laravel

 

Laravel 11 multiple form validation on the same page-WebJourney

 

 Laravel 10,11 Breeze Authentication - WebJourney

 

Laravel 11 Ajax jQuery Crud with Pagination and Live Search

 

Laravel Naming Conventions Accepted by Laravel community

 

Laravel Shorter and More Readable Syntax - WebJourney

Tags

  • Share This: