2017 © Pedro Peláez
 

library ntwindia

Convert number to word in Indian English.

image

ntwindia/ntwindia

Convert number to word in Indian English.

  • Wednesday, August 9, 2017
  • by swashata
  • Repository
  • 1 Watchers
  • 6 Stars
  • 111 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 3 Versions
  • 136 % Grown

The README.md

Number to Words PHP Class - Indian Version

Build Status Code Climate Test Coverage Issue Count, (*1)

This class converts numbers to Indian-English Words. Works for all kinds of numbers including floats. A few examples., (*2)

Examples

  • 10,000,00 - Ten Lakh
  • 3,478 - Three Thousand Four Hundred And Seventy Eight
  • 1,234,567,890 - One Hundred And Twenty Three Crore Forty Five Lakh Sixty Seven Thousand Eight Hundred And Ninty
  • 5,024.78 - Five Thousand Twenty Four And 78/100

Installation

Using Composer

Navigate to your project directory and execute, (*3)

composer require ntwindia/ntwindia, (*4)

If you haven't already, include the composer autoload.php file., (*5)

require_once 'vendor/autoload.php';

Manual Installation

Clone this repository using git, (*6)

git clone git@github.com:swashata/php-number-to-word-india.git

Include the class, (*7)

<?php
require_once 'src/NTWIndia.php';
require_once 'src/Exception/NTWIndiaInvalidNumber.php';
require_once 'src/Exception/NTWIndiaNumberOverflow.php';

Usage

Create an instance, (*8)

<?php
$ntw = new \NTWIndia\NTWIndia();

Convert values, (*9)

<?php
echo $ntw->numToWord( 3104007200 );
// Will print Three Hundred Ten Crore Forty Lakh Seven Thousand Two Hundred

If your number is always less than 100, then use numToWordSmall method to reduce memory usage., (*10)

<?php
echo $ntw->numToWordSmall( 99 );
// Will print Ninty Nine

Methods

Two methods are available, (*11)

numToWord

Converts any number to word including decimal values. Decimals are converted as ... And 986/1000. You will mostly need to call this method., (*12)

Parameters

  • $number: integer|float The number whose word value would be generated.

Return

Returns string The word value of the number. All of the words have uppercased first letter., (*13)

numToWordSmall

Converts numbers smaller than 100 into words. If the number is greater than 99 then it simply calls numToWord., (*14)

Use this when you know your number is lesser than 100 to reduce memory usage., (*15)

Parameters

  • $number: integer The number whose word value would be generated. It does not accepts floating values and will convert to integer if given.

Return

Returns string The word value of the number. All of the words have uppercased first letter., (*16)

Exception Handling

Two exceptions are thrown depending on the condition., (*17)

\NTWIndia\Exception\NTWIndiaInvalidNumber

If you pass a variable to a method which isn't a valid number ( ! is_numeric( $number ) ), (*18)

\NTWIndia\Exception\NTWIndiaNumberOverflow

If pass a number which exceeds the limit., (*19)

  • For numToWord it is the PHP_MAX_INT.
  • For numToWordSmall it is 99.

Translation

To translate, kindly replace the public variables:, (*20)

  • $hundred: Hundred word. Defaults 'Hundred'.
  • $thousand: Thousand word. Defaults 'Thousand'.
  • $lakh: Lakh word. Defaults 'Lakh'.
  • $crore: Crore word. Defaults 'Crore'.
  • $and: And word. Defaults 'And'.
  • $numToWord: Contains mapping of numbers to words. From 0 to 20 and multiple of 10 upto 90.

Unit Test

Unit test is available through composer., (*21)

$ cd /path/to/php-number-to-word-india/
$ composer update
$ vendor/bin/phpunit

It will output something like this., (*22)

Test Case, (*23)

You are more than welcome to add more test cases and send me a pull request., (*24)

Kindly follow Contribution Guide, (*25)

License

PHP Number to Word in Indian Style is licensed under GPLv3, (*26)

Copyright (C) 2017  Swashata Ghosh

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>

The Versions

09/08 2017

dev-master

9999999-dev https://github.com/swashata/php-number-to-word-india

Convert number to word in Indian English.

  Sources   Download

GPL-3.0

The Development Requires

number words number-to-words

09/08 2017

v1.0.1

1.0.1.0 https://github.com/swashata/php-number-to-word-india

Convert number to word in Indian English.

  Sources   Download

GPL-3.0

The Development Requires

number words number-to-words

09/08 2017

v1.0.0

1.0.0.0 https://github.com/swashata/php-number-to-word-india

Convert number to word in Indian English.

  Sources   Download

GPL-3.0

The Development Requires

number words number-to-words