Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Function Reference

num2words ( num )

Description
No description.
 
Parameters
requirednum
 
Code
281  function num2words($num)
282  {
283     $words = "";
284     $A = array("","One", "Two", "Three", "Four", "Five","Six", "Seven", "Eight", "Nine", "Ten","Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen","Sixteen", "Seventeen", "Eighteen", "Nineteen");
285     $B = array("","","Twenty", "Thirty", "Forty", "Fifty","Sixty", "Seventy", "Eighty", "Ninety");
286     $C = array("","","Hundred", "Thousand");
287 
288     $num = str_replace(",","",$num);
289     $num = number_format($num,2,'.','');
290     if (!$num OR !is_numeric($num)) {return false;}
291     $cents = substr($num,strlen($num)-2);
292       $int_length = strpos($num,'.');
293 
294       for ($i=0; $i<=max(0,$int_length-2); $i++) {
295         if ($i==$int_length-2) {
296           $subnum = substr($num,$i,2);
297             if ($subnum<20) {$subword = $A[(int)$subnum];} else {$subword = $B[(int)($subnum/10)] . " " . $A[(int)($subnum%10)];}
298         } else {
299           $subnum = substr($num,$i,1);
300           if ($subnum>0) {$subword = $A[(int)$subnum] . " " . $C[$int_length-$i-1];} else {$subword = "";}
301         }
302         $words .= $subword." ";
303       }
304       $words .= "and $cents/100";
305       return $words;
306  }
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads