title: Issue to Convert Number value To Words in PHP
body: <p>I am using a function to covert number value in words. that is working fine but have a bug in some values like 33,030. this display as (Thirty Three Thousand Three) But should be (Thirty Three Thousand Thirty).
  But same function do correct like this value 2,778 this show correct (Two Thousand Seven Hundred Seventy Eight) function is as below.</p>
  
  <pre><code>      function convertNumberToWord($num){ 
         $decones = array( 
          '01' =&gt; "One", 
          '02' =&gt; "Two", 
          '03' =&gt; "Three", 
          '04' =&gt; "Four", 
          '05' =&gt; "Five", 
          '06' =&gt; "Six", 
          '07' =&gt; "Seven", 
          '08' =&gt; "Eight", 
          '09' =&gt; "Nine", 
          10 =&gt; "Ten", 
          11 =&gt; "Eleven", 
          12 =&gt; "Twelve", 
          13 =&gt; "Thirteen", 
          14 =&gt; "Fourteen", 
          15 =&gt; "Fifteen", 
          16 =&gt; "Sixteen", 
          17 =&gt; "Seventeen", 
          18 =&gt; "Eighteen", 
          19 =&gt; "Nineteen" 
          );
  
      $ones = array( 
          0 =&gt; " ",
          1 =&gt; "One",     
          2 =&gt; "Two", 
          3 =&gt; "Three", 
          4 =&gt; "Four", 
          5 =&gt; "Five", 
          6 =&gt; "Six", 
          7 =&gt; "Seven", 
          8 =&gt; "Eight", 
          9 =&gt; "Nine", 
          10 =&gt; "Ten", 
          11 =&gt; "Eleven", 
          12 =&gt; "Twelve", 
          13 =&gt; "Thirteen", 
          14 =&gt; "Fourteen", 
          15 =&gt; "Fifteen", 
          16 =&gt; "Sixteen", 
          17 =&gt; "Seventeen", 
          18 =&gt; "Eighteen", 
          19 =&gt; "Nineteen" 
          ); 
      $tens = array( 
          0 =&gt; "",
          2 =&gt; "Twenty", 
          3 =&gt; "Thirty", 
          4 =&gt; "Forty", 
          5 =&gt; "Fifty", 
          6 =&gt; "Sixty", 
          7 =&gt; "Seventy", 
          8 =&gt; "Eighty", 
          9 =&gt; "Ninety" 
          ); 
       $hundreds = array( 
          "Hundred", 
          "Thousand", 
          "Million", 
          "Billion", 
          "Trillion", 
          "Quadrillion" 
          ); //limit t quadrillion 
       $num = number_format($num,2,".",","); 
       $num_arr = explode(".",$num); 
       $wholenum = $num_arr[0]; 
       $decnum = $num_arr[1]; 
       $whole_arr = array_reverse(explode(",",$wholenum)); 
       krsort($whole_arr); 
       $rettxt = ""; 
     foreach($whole_arr as $key =&gt; $i){ 
       if($i &lt; 20){ 
      $rettxt .= $ones[$i]; 
     }
    elseif($i &lt; 100){ 
      $rettxt .= $tens[substr($i,0,1)]; 
      $rettxt .= " ".$ones[substr($i,1,1)]; 
    }
    else{ 
      $rettxt .= $ones[substr($i,0,1)]." ".$hundreds[0]; 
      $rettxt .= " ".$tens[substr($i,1,1)]; 
      $rettxt .= " ".$ones[substr($i,2,1)]; 
      } 
    if($key &gt; 0){ 
      $rettxt .= " ".$hundreds[$key]." "; 
    } 
  
    } 
   $rettxt = $rettxt." (SAR)";
  
   if($decnum &gt; 0){ 
    $rettxt .= " and "; 
  if($decnum &lt; 20){ 
      $rettxt .= $decones[$decnum]; 
     }
  elseif($decnum &lt; 100){ 
      $rettxt .= $tens[substr($decnum,0,1)]; 
      $rettxt .= " ".$ones[substr($decnum,1,1)].' Halalal '; 
   }
   $rettxt = $rettxt; 
     } 
   return $rettxt;
  }
  </code></pre>
  
  <p>Help please</p>