If you are building web app for Nepali Client then you may need Nepali number to word system in PHP to print numbers in Nepali word.
There are many open source PHP scripts to convert number to English word in International format but there is no any open source script available in PHP for Nepali Counting system till date. So I decided to write my own script to convert number to Nepali word.
Nepali Number to Word in PHP
Nepali number counting system is quite different than International counting system. We count it One,ten,hundred, thousand, lakh, crore, arab, kharab.
First of all I added all the names of number till 99 to an array named number list. After that I added all the names and values of counting system to the array named mainlist.
private $number_list = array('à¤à¤•', 'दà¥à¤‡', 'तीन', 'चार', 'पाà¤à¤š', 'छ', 'सात', 'आठ', 'नौ', 'दश', 'à¤à¤˜à¤¾à¤°', 'बाहà¥à¤°', 'तेर', 'चौध', 'पनà¥à¤§à¥à¤°', 'सोरà¥à¤¹', 'सतà¥à¤°', 'अठार', 'उनà¥à¤¨à¤¾à¤‡à¤¸', 'बीस','à¤à¤•à¥à¤•à¤¾à¤‡à¤¸', 'बाईस', 'तेइस', 'चौबिस', 'पचà¥à¤šà¥€à¤¸', 'छबà¥à¤¬à¥€à¤¸', 'सतà¥à¤¤à¤¾à¤‡à¤¸', 'अठà¥à¤ ाइस', 'उनà¥à¤¨à¤¤à¥€à¤¸', 'तीस', 'à¤à¤•à¥à¤¤à¥€à¤¸', 'बतà¥à¤¤à¥€à¤¸', 'तेतà¥à¤¤à¥€à¤¸', 'चौतीस', 'पैतिस', 'छतà¥à¤¤à¤¿à¤¸', ' सडà¥à¤¤à¥€à¤¸', 'अडà¥à¤¤à¥€à¤¸', 'उनà¥à¤¨à¤šà¤¾à¤²à¥€à¤¸', 'चालीस','à¤à¤•à¤šà¤¾à¤²à¥€à¤¸', 'बà¥à¤¯à¤¾à¤²à¥€à¤¸', 'तà¥à¤°à¥€à¤šà¤¾à¤²à¥€à¤¸', 'चौबालीस', 'पैतालीस', 'छà¥à¤¯à¤¾à¤²à¥€à¤¸', 'सडà¥à¤šà¤¾à¤²à¥€à¤Ÿà¥à¤ ', 'अडà¥à¤šà¤¾à¤²à¥€à¤¸', 'उनà¥à¤¨à¤ªà¤šà¤¾à¤¸', 'पचास', 'à¤à¤•à¤¾à¤‰à¤¨à¥à¤¨', 'बाउनà¥à¤¨', 'तà¥à¤°à¥€à¤ªà¤¨à¥à¤¨', 'चौबनà¥à¤¨', 'पचà¥à¤ªà¤¨à¥à¤¨', 'छपà¥à¤ªà¤¨à¥à¤¨', 'सनà¥à¤¤à¤¾à¤‰à¤¨à¥à¤¨', 'अनà¥à¤ ाउनà¥à¤¨', 'उननà¥à¤¸à¤¾à¤ à¥à¤ ी', 'साठी','à¤à¤•à¤¸à¤¾à¤ ी', 'बà¥à¤¯à¤¾à¤¸à¤ à¥à¤ ी', 'तà¥à¤°à¥€à¤¸à¤ à¥à¤ ी', 'चौसठà¥à¤ ी', 'पैसठà¥à¤ ी', 'छà¥à¤¯à¤¾à¤¸à¤ à¥à¤ ी', 'सडà¥à¤¸à¤ à¥à¤ ी', 'अठà¥à¤¸à¤ à¥à¤ ी', 'उनà¥à¤¨à¤¸à¤¤à¥à¤¤à¤°à¥€', 'सतà¥à¤¤à¤°à¥€', 'à¤à¤•à¤¤à¥à¤¤à¤°', 'बहतà¥à¤¤à¤°', 'तà¥à¤°à¥€à¤¯à¤¤à¥à¤¤à¤°', 'चौरतà¥à¤¤à¤°', 'पचतà¥à¤¤à¤°', 'छà¥à¤¯à¤¾à¤¤à¤°', 'सतà¥à¤¤à¤°', 'अठà¥à¤…ार', 'उनà¥à¤¨à¤…सी', 'असी','à¤à¤•à¤¾à¤¸à¥€', 'बयासी', 'तà¥à¤°à¥€à¤°à¤¾à¤¸à¥€', 'चौरासी', 'पचासी', 'छà¥à¤¯à¤¾à¤¸à¥€', 'सतासी', 'अठासी', 'उनानबà¥à¤¬à¥‡', 'नबà¥à¤¬à¥‡', 'à¤à¤•à¤¾à¤¨à¤¬à¥à¤¬à¥‡', 'बयानबà¥à¤¬à¥‡', 'तà¥à¤°à¥€à¤¯à¤¾à¤¨à¤¬à¥à¤¬à¥‡', 'चौरानबà¥à¤¬à¥‡', 'पञà¥à¤šà¤¾à¤¨à¤¬à¥à¤¬à¥‡', 'छà¥à¤¯à¤¾à¤¨à¤¬à¥à¤¬à¥‡', 'सनà¥à¤¤à¤¾à¤¨à¤¬à¥à¤¬à¥‡', 'अनà¥à¤ ानबà¥à¤¬à¥‡', 'उनानà¥à¤¸à¤¯');
private $mainlist = array('100000000000'=>'खरव', '1000000000'=>'अरव', '10000000'=>'करोड', '100000'=>'लाख', '1000'=>'हजार', '100'=>'सय');
Function ten() will return the name of number from $number_list array.
Similarly function nepali_name() return the place name and place value name if the remainder is one or above.
The main function of this class is nepali_word(). This function returns the name of given number. I used foreach function to divide given number from all key of $mainlist. Returned name and place name of dividend in variable named result and returned it
The main logic behind this script is dividing input from key of $mainlist and returning remainder and again remainder is divided by another smaller key of $mainlist.
I used function named bcmod() to get remainder because Arithmetic Operators '%' won't work for large numbers.
How to Use Nepali Number to Word?
Download and Upload the script given below to your website and include it. Whenever you need this script, just call like following
$number_word = new number_to_word;
echo $number_word->nepali_word('123456789');
I wrote this script in hurry so It lacks of many features and also it contains a lot of spelling errors. If you find them please suggest me, I will update them. :-)
Hope you liked it, Please share it with your friends... Cheers!!!