title: customize format number to flexible
body: <p>I have php code as following:</p>
  
  <pre><code>&lt;?php
  class number_word {
      private $word_array = array(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",20=&gt;"Twenty",21=&gt;"Twenty-One",22=&gt;"Twenty-Two",23=&gt;"Twenty-Three",24=&gt;"Twenty-Four",25=&gt;"Twenty-Five",26=&gt;"Twenty-Six",27=&gt;"Twenty-Seven",28=&gt;"Twenty-Eight",29=&gt;"Twenty-Nine",30=&gt;"Thirty",31=&gt;"Thirty-One",32=&gt;"Thirty-Two",33=&gt;"Thirty-Three",34=&gt;"Thirty-Four",35=&gt;"Thirty-Five",36=&gt;"Thirty-Six",37=&gt;"Thirty-Seven",38=&gt;"Thirty-Eight",39=&gt;"Thirty-Nine",40=&gt;"Forty",41=&gt;"Forty-One",42=&gt;"Forty-Two",43=&gt;"Forty-Three",44=&gt;"Forty-Four",45=&gt;"Forty-Five",46=&gt;"Forty-Six",47=&gt;"Forty-Seven",48=&gt;"Forty-Eight",49=&gt;"Forty-Nine",50=&gt;"Fifty",51=&gt;"Fifty-One",52=&gt;"Fifty-Two",53=&gt;"Fifty-Three",54=&gt;"Fifty-Four",55=&gt;"Fifty-Five",56=&gt;"Fifty-Six",57=&gt;"Fifty-Seven",58=&gt;"Fifty-Eight",59=&gt;"Fifty-Nine",60=&gt;"Sixty",61=&gt;"Sixty-One",62=&gt;"Sixty-Two",63=&gt;"Sixty-Three",64=&gt;"Sixty-Four",65=&gt;"Sixty-Five",66=&gt;"Sixty-Six",67=&gt;"Sixty-Seven",68=&gt;"Sixty-Eight",69=&gt;"Sixty-Nine",70=&gt;"Seventy",71=&gt;"Seventy-One",72=&gt;"Seventy-Two",73=&gt;"Seventy-Three",74=&gt;"Seventy-Four",75=&gt;"Seventy-Five",76=&gt;"Seventy-Six",77=&gt;"Seventy-Seven",78=&gt;"Seventy-Eight",79=&gt;"Seventy-Nine",80=&gt;"Eighty",81=&gt;"Eighty-One",82=&gt;"Eighty-Two",83=&gt;"Eighty-Three",84=&gt;"Eighty-Four",85=&gt;"Eighty-Five",86=&gt;"Eighty-Six",87=&gt;"Eighty-Seven",88=&gt;"Eighty-Eight",89=&gt;"Eighty-Nine",90=&gt;"Ninety",91=&gt;"Ninety-One",92=&gt;"Ninety-Two",93=&gt;"Ninety-Three",94=&gt;"Ninety-Four",95=&gt;"Ninety-Five",96=&gt;"Ninety-Six",97=&gt;"Ninety-Seven",98=&gt;"Ninety-Eight",99=&gt;"Ninety-Nine",100=&gt;"One Hundred",200=&gt;"Two Hundred",300=&gt;"Three Hundred",400=&gt;"Four Hundred",500=&gt;"Five Hundred",600=&gt;"Six Hundred",700=&gt;"Seven Hundred",800=&gt;"Eight Hundred",900=&gt;"Nine Hundred");
  
      private $thousand = array("", "Thousand, ", "Million, ", "Billion, ", "Trillion, ", "Zillion, ");
  
      private $val, $currency0, $currency1;   
      private $val_array, $dec_value, $dec_word, $num_value, $num_word;
      var $val_word;
  
      public function number_word($in_val = 0, $in_currency0 = "", $in_currency1 = "") {
  
          $this-&gt;val = $in_val;
          $this-&gt;currency0 = $in_currency0;
          $this-&gt;currency1 = $in_currency1;
  
          $this-&gt;val = abs(floatval(str_replace(",","",$this-&gt;val)));
  
          if ($this-&gt;val &gt; 0) {
  
              $this-&gt;val = number_format($this-&gt;val, '2', ',', ',');
  
              $this-&gt;val_array = explode(",", $this-&gt;val);
  
              $this-&gt;dec_value = intval($this-&gt;val_array[count($this-&gt;val_array) - 1]);
  
              if ($this-&gt;dec_value &gt; 0) {
  
                  $this-&gt;dec_word = $this-&gt;word_array[$this-&gt;dec_value]." ".$this-&gt;currency1;
              }
  
              $t = 0;
  
              $this-&gt;num_word = "";
  
              for ($i = count($this-&gt;val_array) - 2; $i &gt;= 0; $i--) {
  
                  $this-&gt;num_value = intval($this-&gt;val_array[$i]);
  
                  if ($this-&gt;num_value == 0) {
                      $this-&gt;num_word = "".$this-&gt;num_word;
                  } 
  
                  elseif (strlen($this-&gt;num_value."") &lt;= 2) {
                      $this-&gt;num_word = $this-&gt;word_array[$this-&gt;num_value]." ".$this-&gt;thousand[$t].$this-&gt;num_word;
                      // add 'and' if not last element in VAL
                      if ($i == 1) {
                          $this-&gt;num_word = " and ".$this-&gt;num_word;
                      }               
                  } 
                  else {
                      $this-&gt;num_word = $this-&gt;word_array[substr($this-&gt;num_value, 0, 1)."00"]. (intval(substr($this-&gt;num_value, 1, 2)) &gt; 0 ? " and " : "") .$this-&gt;word_array[intval(substr($this-&gt;num_value, 1, 2))]." ".$this-&gt;thousand[$t].$this-&gt;num_word;
                  }
                  $t++;
              }       
              if (!empty($this-&gt;num_word)) {
                  $this-&gt;num_word .= " ".$this-&gt;currency0;
              }
          }
          $this-&gt;val_word = $this-&gt;num_word." ".$this-&gt;dec_word;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>code above can be properly read format number 7,052,853.62 but I also want the code able to read other types of formatting numbers, for example; 7.052.853,62 or 7 052 853,62 and when I change comma into dot at line e.g.</p>
  
  <pre><code>    $this-&gt;val = abs(floatval(str_replace(",","",$this-&gt;val)));
      if ($this-&gt;val &gt; 0) {
                      $this-&gt;val = number_format($this-&gt;val, '2', ',', ',');
  
                      $this-&gt;val_array = explode(",", $this-&gt;val);
  </code></pre>
  
  <p>UPDATE:
  testing:</p>
  
  <blockquote>
    <p>echo $nw->number_word('52,853.62',
    'Dollar', 'Cent');</p>
  </blockquote>
  
  <p>then the code can no longer read the cent format number, what i should do to fix it? any pointers I would appreciate and thanks</p>