DEV Community

yoosef alipour
yoosef alipour

Posted on • Updated on

Numera: A PHP Library for Number to Words Conversion

As a developer, you may have encountered situations where you need to convert numbers to words or vice versa. This can be a tedious task, especially when dealing with large numbers or multiple languages. That's where Numera comes in - a powerful PHP library that makes number to words conversion a breeze.

In this article, we'll explore the features and benefits of Numera, and show you how to use it in your PHP projects.

What is Numera?

Numera is a PHP library that provides a simple and efficient way to convert numbers to words and vice versa. It supports multiple languages, including English and Persian, with more languages to come. Numera is designed to be easy to use and extend, making it a great tool for any PHP project.

Features of Numera

Numera has a range of features that make it a powerful tool for number to words conversion. Some of the key features include:

  • Number to Words Conversion: Convert numbers to words in a variety of languages.
  • Words to Number Conversion: Convert words to numbers in a variety of languages.
  • Camel Case Support: Output words in camel case for easier readability.
  • Multi-Language Support: Supports multiple languages, with more languages to come.
  • Easy to Use: Simple and intuitive API makes it easy to use Numera in your projects.
  • Easy to Extend: Numera is designed to be easy to extend, making it simple to add support for new languages.

Install via Composer

You can install Numera using Composer:

composer require pinoox/numera
Enter fullscreen mode Exit fullscreen mode

How to Use Numera

Using Numera is straightforward. Here's an example of how to convert a number to words:

use Pino\Numera;

$numera = Numera::init('en'); // Initialize with English locale
$result = $numera->convertToWords(4454545156);
echo $result; // Output: "four billion, four hundred fifty-four million, five hundred forty-five thousand, one hundred fifty-six"
Enter fullscreen mode Exit fullscreen mode

Converting words to numbers is just as easy:

$result = $numera->convertToNumber('four billion, four hundred fifty-four million, five hundred forty-five thousand, one hundred fifty-six');
echo $result; // Output: 4454545156
Enter fullscreen mode Exit fullscreen mode

Benefits of Using Numera

There are several benefits to using Numera in your PHP projects. Some of the key benefits include:

  • Saves Time: Numera saves you time and effort by providing a simple and efficient way to convert numbers to words and vice versa.
  • Improves Readability: Numera's camel case support makes it easy to output words in a readable format.
  • Multi-Language Support: Numera's support for multiple languages makes it a great tool for international projects.
  • Easy to Use: Numera's simple and intuitive API makes it easy to use, even for developers with limited experience.

Get Started with Numera

To get started with Numera, head over to the Numera GitHub repository and follow the installation instructions. You can also check out the Numera documentation for more information on how to use Numera in your projects.

Conclusion

Numera is a powerful and flexible PHP library that makes number to words conversion a breeze. With its support for multiple languages, camel case output, and easy-to-use API, Numera is a great tool for any PHP project. Whether you're working on a simple website or a complex application, Numera is definitely worth considering.

Top comments (3)

Collapse
 
zunaidmiah profile image
Zunaid Miah

That's really cool.

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

Might want to switch en to en-us as the output is definitely not correct for British English

Collapse
 
yoosefap profile image
yoosef alipour

Regarding your comment about switching from "en" to "en-us" for more accurate output in American English, I completely agree.

See the Translation Guide on GitHub:
github.com/pinoox/numera/blob/mast...

It would be a pleasure if you were to contribute to the development.