daily pastebin goal
6%
SHARE
TWEET

PHP Function Integer To Alphabet (Indonesia Version)

masardee Jun 23rd, 2011 358 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Integer To Alphabet
  3.  * to convert integer variable to alphabet string
  4.  *
  5.  * @author              Ardi Imawan (ardiimawan@gmail.com)
  6.  * @param               $number int
  7.  * @param               $se boolean
  8.  * @return              string
  9.  **/
  10. public function _integer_to_alphabet($number, $se = false)
  11. {
  12.         if($number == 0) return "NOL";
  13.        
  14.         $alphabet = "";
  15.         $satuan = array(
  16.                 (object)array('digit' => 12, 'alphabet' => 'TRILIUN'),
  17.                 (object)array('digit' => 9, 'alphabet' => 'MILYAR'),
  18.                 (object)array('digit' => 6, 'alphabet' => 'JUTA'),
  19.                 (object)array('digit' => 3, 'alphabet' => 'RIBU'),
  20.                 (object)array('digit' => 2, 'alphabet' => 'RATUS')
  21.         );     
  22.        
  23.         if(strlen($number) > 2)
  24.         {
  25.                 foreach($satuan as $row)
  26.                 {              
  27.                         if(strlen($number) > $row->digit)
  28.                         {
  29.                                 $_int_temp = (int)substr($number, 0, $row->digit*-1);
  30.                                 $alphabet .= $this->_integer_to_alphabet($_int_temp, $row->digit == 3  && $_int_temp == 1 || $row->digit == 2) . "$row->alphabet ";
  31.                                 $number = ((int)substr($number, $row->digit*-1))."";
  32.                         }
  33.                 }
  34.         }
  35.        
  36.         // puluhan
  37.         if(strlen($number) > 1)
  38.         {
  39.                 $_int_temp = (int)substr($number, 0, -1);
  40.                 if($_int_temp == 1 && (int)substr($number, -1) > 0)
  41.                 {
  42.                         $number = (int)substr($number, -1);
  43.                         $alphabet .= $this->_integer_to_alphabet($number, true) . "BELAS ";
  44.                         $number = "";
  45.                 }
  46.                 else
  47.                 {
  48.                         $alphabet .= $this->_integer_to_alphabet($_int_temp, $_int_temp == 1) . "PULUH ";
  49.                         $number = (int)substr($number, -1);
  50.                 }
  51.                
  52.         }
  53.         // satuan              
  54.         if($se && $number == 1) $alphabet .= "SE";
  55.         else if($number == 1) $alphabet .= "SATU ";
  56.         else if($number == 2) $alphabet .= "DUA ";
  57.         else if($number == 3) $alphabet .= "TIGA ";
  58.         else if($number == 4) $alphabet .= "EMPAT ";
  59.         else if($number == 5) $alphabet .= "LIMA ";
  60.         else if($number == 6) $alphabet .= "ENAM ";
  61.         else if($number == 7) $alphabet .= "TUJUH ";
  62.         else if($number == 8) $alphabet .= "DELAPAN ";
  63.         else if($number == 9) $alphabet .= "SEMBILAN ";
  64.        
  65.         return $alphabet;
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top