Ver Mensaje Individual
  #14 (permalink)  
Antiguo 18/11/2008, 15:26
rangermid
 
Fecha de Ingreso: octubre-2008
Mensajes: 25
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: Convertir nuemero a texto

Por si a alguien le interesa la funcion con Centavos y en Moneda Nacional Mexico!!!

Código PHP:
<?
$numerodec
=12563.25;
$numeros =    array("-""UNO""DOS""TRES""CUATRO""CINCO""SEIS""SIETE""OCHO""NUEVE");
$numerosX =   array("-""UN""DOS""TRES""CUATRO""CINCO""SEIS""SIETE""OCHO""NUEVE");
$numeros100 = array("-""CIENTO""DOSCIENTOS""TRESCIENTOS""CUATROCIENTOS""QUINIENTOS""SEISCIENTOS""SETECIENTOS""OCHOCIENTOS""NOVECIENTOS");
$numeros11 =  array("-""ONCE""DOCE""TRECE""CATORCE""QUINCE""DIECISEIS""DIECISIETE""DIECIOCHO""DIECINUEVE");
$numeros10 =  array("-""-""-""TREINTA""CUARENTA""CINCUENTA""SESENTA""SETENTA""OCHENTA""NOVENTA");


function 
tresnumeros($n$last) {
 global 
$numeros100$numeros10$numeros11$numeros$numerosX;
  if (
$n == 100) return "CIEN ";
  if (
$n == 0) return "CERO ";
  
$r "";
  
$cen floor($n 100);
  
$dec floor(($n &#37; 100) / 10);
  
$uni $n 10;
if (
$cen 0$r .= $numeros100[$cen] . " ";

            switch (
$dec) {
                case 
0$special 0; break;
                case 
1$special 10; break;
                case 
2$special 20; break;
                default: 
$r .= $numeros10[$dec] . " "$special 30; break;
            }
            if (
$uni == 0) {
                if (
$special==30);
                else if (
$special==20$r .= "VEINTE ";
                else if (
$special==10$r .= "DIEZ ";
                else if (
$special==0);
            } else {
                if (
$special == 30 && !$last$r .= "Y " $numerosX[$n%10] . " ";
                else if (
$special == 30$r .= "Y " $numeros[$n%10] . " ";
                else if (
$special == 20) {
                    if (
$uni == 3$r .= "VEINTITRES ";
                    else if (!
$last$r .= "VEINTI" $numerosX[$n%10] . " ";
                    else 
$r .= "VEINTI" $numeros[$n%10] . " ";
                } else if (
$special == 10$r .= $numeros11[$n%10] . " ";
                else if (
$special == && !$last$r .= $numerosX[$n%10] . " ";
                else if (
$special == 0$r .= $numeros[$n%10] . " ";
            }
            return 
$r;
        }

        function 
seisnumeros($n$last) {
            if (
$n == 0) return "CERO ";
            
$miles floor($n 1000);
            
$units $n 1000;
            
$r "";
            if (
$miles == 1$r .= "MIL ";
            else if (
$miles 1$r .= tresnumeros($milesfalse) . "MIL ";
            if (
$units 0$r .= tresnumeros($units$last);
            return 
$r;
        }

        function 
docenumeros($n) {
            if (
$n == 0) return "CERO ";
            
$millo floor($n 1000000);
            
$units $n 1000000;
            
$r "";
            if (
$millo == 1$r .= "UN MILLON ";
            else if (
$millo 1$r .= seisnumeros($millofalse) . "MILLONES ";
            if (
$units 0$r .= seisnumeros($unitstrue);
            return 
$r;
        }  
        
        function 
desglosar$numerodec ) {
        
$patron  ".";
        
$posicion strpos($numerodec,$patron);
        
$decimalessubstr($numerodec,$posicion ,2);
        if (
strstr($numerodec,$patron))
         return 
"PESOS $decimales/100 M.N.";
         else
         return 
"PESOS CON 00/100 M.N.";
         
        } 
        echo 
docenumeros$numerodec );
        echo 
desglosar$numerodec );
?>
Devuelve:
DOCE MIL QUINIENTOS SESENTA Y TRES PESOS 25/100 M.N.

Saludos, si ven algo mal, avisenme


Obvio que el numero ya debe llegar redondeado a 2 decimales :)