PHP Code to Convert Numeric Value into Text Format

convert integer to text format in php
Many a times, in our applications we need to convert number to text format. Till now, we have to write our own logic for it. But a good news for software developers that PHP has introduced a new class with name “Num2Text” that helps converting a number into respective text value.

How to Convert a Number to Text using PHP

For using this, you just need to get the required PHP class files, include it into your code and just get your purpose fulfilled.

Please go to the Link Below:

http://www.phpclasses.org/browse/package/9310/download/zip.html

And get the fresh copy of the whole code containing the Num2Text class file, along with an example to use it.

You will get it in zipped form that you need to extract to get the code files. Inside the folder you will get two version of Num2Text class:

Num2TextEng

( this class is used to get the text value of supplied number into most commonly used English language.

Num2TextSpanish

( this class is used to get the text value of supplied number into Spanish language)

And here is the example code, showing the use of Num2text classes:

Output: forty-five

With this class, you can easily get text equivalent of numbers with any number of digits of your choice.

e.g. Lets take the example of a big number

Output: forty-five million, six hundred and forty-five thousand, six hundred and forty-five

Likewise, to get the text format in Spanish language, you just need to include the Spanish counterpart of Num2TextEng class.

As follows:

require_once ‘Num2TextSpanish.php’;

Hope, it will ease the developers work a bit. Thanks

Recommended Posts For You

About Manish Kumar

I am PHP web developer and blogger.

View all posts by Manish Kumar

Leave a Comment

Your email address will not be published. Required fields are marked *