BBnepal-Accounts/account/application/libraries/Numbertoword.php

101 lines
6.1 KiB
PHP
Raw Normal View History

2024-07-10 12:43:19 +00:00
<?php
class numbertoword
{
//Free number to Nepali word converter by http://pujann.com.np
//GPU License
private function check_valid_number($nums)
{// use $nums > PHP_INT_MAX if error occurred for large numbers
if($nums>9900000000000)
{
throw new Exception("गणकले गन्न सक्ने भन्दा बढी नम्बर हाल्नुभो");
}
}
private $number_list = array('एक', 'दुइ', 'तीन', 'चार', 'पाँच', 'छ', 'सात', 'आठ', 'नौ', 'दश', 'एघार', 'बाह्र', 'तेर', 'चौध', 'पन्ध्र', 'सोर्ह', 'सत्र', 'अठार', 'उन्नाइस', 'बीस','एक्काइस', 'बाईस', 'तेइस', 'चौबिस', 'पच्चीस', 'छब्बीस', 'सत्ताइस', 'अठ्ठाइस', 'उन्नतीस', 'तीस', 'एक्तीस', 'बत्तीस', 'तेत्तीस', 'चौतीस', 'पैतिस', 'छत्तिस', ' सड्तीस', 'अड्तीस', 'उन्नचालीस', 'चालीस','एकचालीस', 'ब्यालीस', 'त्रीचालीस', 'चौबालीस', 'पैतालीस', 'छ्यालीस', 'सड्चालीट्ठ', 'अड्चालीस', 'उन्नपचास', 'पचास', 'एकाउन्न', 'बाउन्न', 'त्रीपन्न', 'चौबन्न', 'पच्पन्न', 'छप्पन्न', 'सन्ताउन्न', 'अन्ठाउन्न', 'उनन्साठ्ठी', 'साठी','एकसाठी', 'ब्यासठ्ठी', 'त्रीसठ्ठी', 'चौसठ्ठी', 'पैसठ्ठी', 'छ्यासठ्ठी', 'सड्सठ्ठी', 'अठ्सठ्ठी', 'उन्नसत्तरी', 'सत्तरी', 'एकत्तर', 'बहत्तर', 'त्रीयत्तर', 'चौरत्तर', 'पचत्तर', 'छ्यातर', 'सत्तर', 'अठ्अार', 'उन्नअसी', 'असी','एकासी', 'बयासी', 'त्रीरासी', 'चौरासी', 'पचासी', 'छ्यासी', 'सतासी', 'अठासी', 'उनानब्बे', 'नब्बे', 'एकानब्बे', 'बयानब्बे', 'त्रीयानब्बे', 'चौरानब्बे', 'पञ्चानब्बे', 'छ्यानब्बे', 'सन्तानब्बे', 'अन्ठानब्बे', 'उनान्सय');
private $mainlist = array('100000000000'=>'खरव', '1000000000'=>'अरव', '10000000'=>'करोड', '100000'=>'लाख', '1000'=>'हजार', '100'=>'सय');
private $eng_number_list = array("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Twenty One", "Twenty Two", "Twenty Three", "Twenty Four", "Twenty Five", "Twenty Six", "Twenty Seven", "Twenty Eight", "Twenty Nine", "Thirty", "Thirty One", "Thirty Two", "Thirty Three", "Thirty Four", "Thirty Five", "Thirty Six", "Thirty Seven", "Thirty Eight", "Thirty Nine", "Fourty", "Fourty One", "Fourty Two", "Fourty Three", "Fourty Four", "Fourty Five", "Fourty Six", "Fourty Seven", "Fourty Eight", "Fourty Nine", "Fifty", "Fifty One", "Fifty Two", "Fifty Three", "Fifty Four", "Fifty Five", "Fifty Six", "Fifty Seven", "Fifty Eight", "Fifty Nine", "Sixty", "Sixty One", "Sixty Two", "Sixty Three", "Sixty Four", "Sixty Five", "Sixty Six", "Sixty Seven", "Sixty Eight", "Sixty Nine", "Seventy", "Seventy One", "Seventy Two", "Seventy Three", "Seventy Four", "Seventy Five", "Seventy Six", "Seventy Seven", "Seventy Eight", "Seventy Nine", "Eighty", "Eighty One", "Eighty Two", "Eighty Three", "Eighty Four", "Eighty Five", "Eighty Six", "Eighty Seven", "Eighty Eight", "Eighty Nine", "Ninety", "Ninety One", "Ninety Two", "Ninety Three", "Ninety Four", "Ninety Five", "Ninety Six", "Ninety Seven", "Ninety Eight","Ninety Nine");
private $eng_mainlist = array('100000000000'=>'Kharba', '1000000000'=>'Arba', '10000000'=>'Karod', '100000'=>'Lakh', '1000'=>'Thousands', '100'=>'Hundred');
private function ten($nums)
{
if ($nums>0) {
return $this->number_list[$nums-1];
}
}
private function eng_ten($nums)
{
if ($nums>0) {
return $this->eng_number_list[$nums-1];
}
}
private function nepali_name($nums, $divident)
{
$number = floor($nums/$divident);
if($number>0)
{
return $this->number_list[$number-1].' '.$this->mainlist[$divident];
}
}
public function nepali_word($nums)
{
$n=explode(".",$nums);
$nums = abs($nums);
$this->check_valid_number($nums);
$result = '';
$coll="";
foreach ($this->mainlist as $count => $name)
{
$result.= $this->nepali_name($nums, $count).' ';
$nums = bcmod($nums,$count);
if($nums<=99)
{
$result.= $this->ten($nums);
$coll=$result;
}
}
if(isset($n[1]))$coll.=" रुपैयाँ ".$this->ten($n[1])." पैसा";
return $coll." मात्र";
}
private function english_name($nums, $divident)
{
$number = floor($nums/$divident);
if($number>0)
{
return $this->eng_number_list[$number-1].' '.$this->eng_mainlist[$divident];
}
}
public function english_word($nums)
{
$n=explode(".",$nums);
$nums=$n[0];
$nums = abs($nums);
$this->check_valid_number($nums);
$result = '';
$coll='';
foreach ($this->eng_mainlist as $count => $name)
{
$result.= $this->english_name($nums, $count).' ';
$nums = bcmod($nums,$count);
if($nums<=99)
{
$result.= $this->eng_ten($nums);
$coll=$result;
}
}
if(isset($n[1]))$coll.=" And ".$this->eng_decimal_part($n[1])." Paisa";
return $coll." Only";
}
private function eng_decimal_part($decimal)
{
return $this->eng_ten($decimal);
/* //IF WANT TO RETURN 68 Paisa as SIX EIGHT Paisa
$digits=str_split($decimal);
$n="";
foreach($digits as $d)
{
$n.=$this->eng_number_list[$d-1]." ";
}
return $n;
*/
}
}