Example #1
0
function traducirCifra($number)
{
    // Mandarlo a que tradusca la cantidad en letra.
    if ($number == 0) {
        // if amount = 0, then forget all about conversions,
        $hundreds_final_string = " cero ";
        // amount is zero (cero). handle it externally, to
        // function breakdown
    } else {
        $millions = whole_part($number, 1000000);
        // first, send the millions to the string
        $number = mod($number, 1000000);
        // conversion function
        if ($millions != 0) {
            // This condition handles the plural case
            if ($millions == 1) {
                // if only 1, use 'millon' (million). if
                $descriptor = " millon, ";
                // > than 1, use 'millones' (millions) as
            } else {
                // a descriptor for this triad.
                $descriptor = " millones, ";
            }
        } else {
            $descriptor = " ";
            // if 0 million then use no descriptor.
        }
        $millions_final_string = string_literal_conversion($millions) . $descriptor;
        $thousands = whole_part($number, 1000);
        // now, send the thousands to the string
        $number = mod($number, 1000);
        // conversion function.
        if ($thousands != 0) {
            // This condition eliminates the descriptor
            $descriptor = " mil, ";
            // if there are no thousands on the amount
        } else {
            $descriptor = " ";
        }
        $thousands_final_string = string_literal_conversion($thousands) . $descriptor;
        // this will handle numbers between 1 and 999 which
        // need no descriptor whatsoever.
        $hundreds = $number;
        $hundreds_final_string = string_literal_conversion($hundreds);
    }
    //end if ($number ==0)
    $millions_final_string = strtoupper($millions_final_string);
    $thousands_final_string = strtoupper($thousands_final_string);
    $hundreds_final_string = strtoupper($hundreds_final_string);
    //$t->set_var("IMPORTE_LETRA",$millions_final_string.$thousands_final_string.$hundreds_final_string." USD 00/100 CTS.");
    $importeLetra = $millions_final_string . $thousands_final_string . $hundreds_final_string;
    return $importeLetra;
}
Example #2
0
function covertirNumLetras($number)
{
   $millions_final_string="";
   $thousands_final_string="";
  //number = number_format (number, 2);
   $number1=$number.'';
   //settype (number, "integer");
   $cent = explode('.',$number);  
   if (isset($cent[1]) ){
	   $centavos = $cent[1];
	  }else{
	  $centavos = "00";
	  }
   
   $number= $cent[0];
      

   if ($number == 0 || $number == "") 
   { // if amount = 0, then forget all about conversions, 
      $centenas_final_string=" cero "; // amount is zero (cero). handle it externally, to 
      // function breakdown 
  } 
   else 
   { 
   
     $millions  = ObtenerParteEntDiv($number, 1000000); // first, send the millions to the string 
      $number = mod($number, 1000000);           // conversion function 
      
     if ($millions != 0)
      {                      
      // This condition handles the plural case 
         if ($millions == 1) 
         {              // if only 1, use 'millon' (million). if 
            $descriptor= " millon ";  // > than 1, use 'millones' (millions) as 
            } 
         else 
         {                           // a descriptor for this triad. 
              $descriptor = " millones "; 
            } 
      } 
      else 
      {    
         $descriptor = " ";                 // if 0 million then use no descriptor. 
      } 
      $millions_final_string = string_literal_conversion($millions).$descriptor; 
          
      
      $thousands = ObtenerParteEntDiv($number, 1000);  // now, send the thousands to the string 
        $number = mod($number, 1000);            // conversion function. 
      //print "Th:".thousands;
     if ($thousands != 1) 
      {                   // This condition eliminates the descriptor 
         $thousands_final_string =string_literal_conversion($thousands) . " mil "; 
       //  descriptor = " mil ";          // if there are no thousands on the amount 
      } 
      if ($thousands == 1)
      {
         $thousands_final_string = " mil "; 
     }
      if ($thousands < 1) 
      { 
         $thousands_final_string = " "; 
      } 
  
      // this will handle numbers between 1 and 999 which 
      // need no descriptor whatsoever. 

     $centenas  = $number;                     
      $centenas_final_string = string_literal_conversion($centenas) ; 
      
   } //end if (number ==0) 

   /*if (ereg("un",centenas_final_string))
   {
     centenas_final_string = ereg_replace("","o",centenas_final_string); 
   }*/
   //finally, print the output. 

   /* Concatena los millones, miles y cientos*/
   $cad = $millions_final_string.$thousands_final_string.$centenas_final_string; 
   
   /* Convierte la cadena a Mayúsculas*/
   $cad = strtoupper($cad);       

   if (strlen($centavos)>2)
   {   
      if(substr($centavos,2,2)>= 5){
         $centavos = substr($centavos,0,2)+(intval(substr($centavos,1,2))+1);
      }   else{
        $centavos = substr($centavos,0,3);
       }
   }

   /* Concatena a los centavos la cadena "/100" */
   if (strlen($centavos)==1)
   {
      $centavos = $centavos."0";
   }
   $centavos = $centavos. "/100"; 


   /* Asigna el tipo de moneda, para 1 = PESO, para distinto de 1 = PESOS*/
   if ($number == 1)
   {
      $moneda = " PESO ";  
   }
   else
   {
      $moneda = " PESOS ";  
   }
   /* Regresa el número en cadena entre paréntesis y con tipo de moneda y la fase M.N.*/
   $importe=$cad.$moneda.$centavos." M.N.";
   return $importe;
}