msaied/money-to-words-converter

A php library that converts any money value in digit in any language or numeric system to its words in any language

2.0.3 2021-06-14 15:46 UTC

This package is auto-updated.

Last update: 2024-11-03 05:54:33 UTC


README

Packagist Build Status PHP from Packagist Packagist

A php library that converts any money value in digit in any language or numeric system to its words in any language

Installation

composer require msaied/money-to-words-converter
  • Or edit your project's composer.json to require msaied/money-to-words-converter and then run composer update.
"require": {
    "msaied/money-to-words-converter": "^2"
}

Example

For working example, checkout the Example folder.

Usage

Note: You should have composer's autoloader included require 'vendor/autoload.php'

Always include Converter namespace to your php file

Basic usage

use TNkemdilim\MoneyToWords\Converter;

// Nigerian currency : naira & kobo
$converter = new Converter("naira", "kobo");
echo ($converter->convert(374));
echo ($converter->convert(23.45));
echo ($converter->convert(748247284782));
echo ($converter->convert(748247284782.34));
echo ($converter->convert('34'));
echo ($converter->convert('2345.34'));
echo ($converter->convert('3453345'));

Other Languages

To convert money value to other languages, you'll need to import the Languages namespace

use TNkemdilim\MoneyToWords\Converter;
use TNkemdilim\MoneyToWords\Languages as Language;

$converter = new Converter("naira", "kobo", Language::FRENCH);

echo ($converter->convert(23.45));
echo ($converter->convert("748247284782"));

Convertion From Other Numeric System

Conversion from other numeric systems are supported in-built, and by default needs no extra configuration to convert into words.

Read more about Numeric systems.

// Chinese numeric system
$money = "八百七十二万七千八百二十四";

// Example 1
$converter = new Converter("yen", "sen");
echo ($converter->convert($money));

// Example 2: but convert money value to french
$frenchConverter = new Converter("yen", "sen", Language::FRENCH);
echo ($frenchConverter->convert("八百七十二万七千八百二十四"));

Change Currency

To change the currency of the money to convert

//  Dollars & Cents
$converter->setCurrency("dollar", "cents");
echo ($converter->convert(234.34)); // two hundred and thirty-four dollars, thirty-four cents only.

// Pounds & Pence
$converter->setCurrency("pounds", "pence");
echo ($converter->convert('23.3')); // twenty three pounds, 3 pence only.

Change Language Translation

Language for translation can be easily changed as follows. All available languages can be accessed via the TNkemdilim\MoneyToWords\Languages class.

See all available in Languages.

use TNkemdilim\MoneyToWords\Languages as Language;

$converter->setLanguage(Language::LATIN);
$converter->setLanguage(Language::SWAHILI);
$converter->setLanguage(Language::GREEK);

Supported Languages

For more conversion types

Thanks To

Tochukwu Nkemdilim

https://github.com/TNkemdilim/Money-To-Words-Converter

License

MIT © Tochukwu Nkemdilim