2018-12-30 Pujan Niroula 2 Minute(s) Read

Convert Number to Nepali Word in PHP

img-number nepali word php.jpg

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!!!

Download Attached Files: Number to Nepali Word System in PHP.zip
Comments (4) Add New Comment
Bikesh Sharma2020-09-01 7:22 AM

Thanks, works like charm ! Please create it in JS.

Reply
ksv2021-05-01 11:47 AM

Thankyou for wonderful creation but can you please create this for JS, i found this one but not working properly for many instances https://github.com/prdpspkt/nepali-english-numbers-to-nepali-unicode-text