Foros del Web » Programando para Internet » PHP »

necesito funcion que convierta numeros a letra

Estas en el tema de necesito funcion que convierta numeros a letra en el foro de PHP en Foros del Web. como lo dice el titulo, encontre muchas pero tienen varios bugs... necesito que sepa contar desde 1 a un millon y lea decimales......
  #1 (permalink)  
Antiguo 30/04/2010, 11:09
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
necesito funcion que convierta numeros a letra

como lo dice el titulo, encontre muchas pero tienen varios bugs...
necesito que sepa contar desde 1 a un millon y lea decimales...
  #2 (permalink)  
Antiguo 30/04/2010, 11:10
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: necesito funcion que convierta numeros a letra

Y ¿por qué mejor no arreglas los bugs? Así aprendes a desenvolverte bien en php.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #3 (permalink)  
Antiguo 30/04/2010, 11:14
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: necesito funcion que convierta numeros a letra

lo intente, pero es muy dificil...incluso lo hice con un amigo mio, y ni juntos lo logramos...
  #4 (permalink)  
Antiguo 30/04/2010, 11:35
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: necesito funcion que convierta numeros a letra

bueno, encontre una funcion q lo hace bastante bien, pero quisiera q dsp de decir todo el numero cuando hay decimal termine diciendo "centavos"...
Código PHP:
Ver original
  1. <?php
  2. /*!
  3.   @function num2letras ()
  4.   @abstract Dado un número lo devuelve escrito.
  5.   @param $num number - Número a convertir.
  6.   @param $fem bool - Forma femenina (true) o no (false).
  7.   @param $dec bool - Con decimales (true) o no (false).
  8.   @result string - Devuelve el número escrito en letra.
  9. */
  10. function num2letras($num, $fem = true, $dec = true) {
  11. //if (strlen($num) > 14) die("El número introducido es demasiado grande");
  12.    $matuni[2]  = "dos";
  13.    $matuni[3]  = "tres";
  14.    $matuni[4]  = "cuatro";
  15.    $matuni[5]  = "cinco";
  16.    $matuni[6]  = "seis";
  17.    $matuni[7]  = "siete";
  18.    $matuni[8]  = "ocho";
  19.    $matuni[9]  = "nueve";
  20.    $matuni[10] = "diez";
  21.    $matuni[11] = "once";
  22.    $matuni[12] = "doce";
  23.    $matuni[13] = "trece";
  24.    $matuni[14] = "catorce";
  25.    $matuni[15] = "quince";
  26.    $matuni[16] = "dieciseis";
  27.    $matuni[17] = "diecisiete";
  28.    $matuni[18] = "dieciocho";
  29.    $matuni[19] = "diecinueve";
  30.    $matuni[20] = "veinte";
  31.    $matunisub[2] = "dos";
  32.    $matunisub[3] = "tres";
  33.    $matunisub[4] = "cuatro";
  34.    $matunisub[5] = "quin";
  35.    $matunisub[6] = "seis";
  36.    $matunisub[7] = "sete";
  37.    $matunisub[8] = "ocho";
  38.    $matunisub[9] = "nove";
  39.    $matdec[2] = "veint";
  40.    $matdec[3] = "treinta";
  41.    $matdec[4] = "cuarenta";
  42.    $matdec[5] = "cincuenta";
  43.    $matdec[6] = "sesenta";
  44.    $matdec[7] = "setenta";
  45.    $matdec[8] = "ochenta";
  46.    $matdec[9] = "noventa";
  47.    $matsub[3]  = 'mill';
  48.    $matsub[5]  = 'bill';
  49.    $matsub[7]  = 'mill';
  50.    $matsub[9]  = 'trill';
  51.    $matsub[11] = 'mill';
  52.    $matsub[13] = 'bill';
  53.    $matsub[15] = 'mill';
  54.    $matmil[4]  = 'millones';
  55.    $matmil[6]  = 'billones';
  56.    $matmil[7]  = 'de billones';
  57.    $matmil[8]  = 'millones de billones';
  58.    $matmil[10] = 'trillones';
  59.    $matmil[11] = 'de trillones';
  60.    $matmil[12] = 'millones de trillones';
  61.    $matmil[13] = 'de trillones';
  62.    $matmil[14] = 'billones de trillones';
  63.    $matmil[15] = 'de billones de trillones';
  64.    $matmil[16] = 'millones de billones de trillones';
  65.    $num = trim((string)@$num);
  66.    if ($num[0] == '-') {
  67.       $neg = 'menos ';
  68.       $num = substr($num, 1);
  69.    }else
  70.       $neg = '';
  71.    while ($num[0] == '0') $num = substr($num, 1);
  72.    if ($num[0] < '1' or $num[0] > 9) $num = '0' . $num;
  73.    $zeros = true;
  74.    $punt = false;
  75.    $ent = '';
  76.    $fra = '';
  77.    for ($c = 0; $c < strlen($num); $c++) {
  78.       $n = $num[$c];
  79.       if (! (strpos(".,'''", $n) === false)) {
  80.          if ($punt) break;
  81.          else{
  82.             $punt = true;
  83.             continue;
  84.          }
  85.       }elseif (! (strpos('0123456789', $n) === false)) {
  86.          if ($punt) {
  87.             if ($n != '0') $zeros = false;
  88.             $fra .= $n;
  89.          }else
  90.             $ent .= $n;
  91.       }else
  92.          break;
  93.    }
  94.    
  95.    $ent = '     ' . $ent;
  96.    
  97.    if ($dec and $fra and ! $zeros) {
  98.       $fin = ' con';
  99.       for ($n = 0; $n < strlen($fra); $n++) {
  100.          if (($s = $fra[$n]) == '0')
  101.             $fin .= ' cero';
  102.          elseif ($s == '1')
  103.             $fin .= $fem ? ' uno' : ' un';
  104.          else
  105.             $fin .= ' ' . $matuni[$s];
  106.       }
  107.    }else
  108.       $fin = '';
  #5 (permalink)  
Antiguo 30/04/2010, 11:36
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: necesito funcion que convierta numeros a letra

Código PHP:
Ver original
  1. if ((int)$ent === 0) return 'Cero ' . $fin;
  2.    $tex = '';
  3.    $sub = 0;
  4.    $mils = 0;
  5.    $neutro = false;
  6.    
  7.    while ( ($num = substr($ent, -3)) != '   ') {
  8.      
  9.       $ent = substr($ent, 0, -3);
  10.       if (++$sub < 3 and $fem) {
  11.          $matuni[1] = 'uno';
  12.          $subcent = 'as';
  13.       }else{
  14.          $matuni[1] = $neutro ? 'un' : 'uno';
  15.          $subcent = 'os';
  16.       }
  17.       $t = '';
  18.       $n2 = substr($num, 1);
  19.       if ($n2 == '00') {
  20.       }elseif ($n2 < 21)
  21.          $t = ' ' . $matuni[(int)$n2];
  22.       elseif ($n2 < 30) {
  23.          $n3 = $num[2];
  24.          if ($n3 != 0) $t = 'i' . $matuni[$n3];
  25.          $n2 = $num[1];
  26.          $t = ' ' . $matdec[$n2] . $t;
  27.       }else{
  28.          $n3 = $num[2];
  29.          if ($n3 != 0) $t = ' y ' . $matuni[$n3];
  30.          $n2 = $num[1];
  31.          $t = ' ' . $matdec[$n2] . $t;
  32.       }
  33.      
  34.       $n = $num[0];
  35.       if ($n == 1) {
  36.          $t = ' ciento' . $t;
  37.       }elseif ($n == 5){
  38.          $t = ' ' . $matunisub[$n] . 'ient' . $subcent . $t;
  39.       }elseif ($n != 0){
  40.          $t = ' ' . $matunisub[$n] . 'cient' . $subcent . $t;
  41.       }
  42.      
  43.       if ($sub == 1) {
  44.       }elseif (! isset($matsub[$sub])) {
  45.          if ($num == 1) {
  46.             $t = ' mil';
  47.          }elseif ($num > 1){
  48.             $t .= ' mil';
  49.          }
  50.       }elseif ($num == 1) {
  51.          $t .= ' ' . $matsub[$sub] . 'ón';
  52.       }elseif ($num > 1){
  53.          $t .= ' ' . $matsub[$sub] . 'ones';
  54.       }  
  55.       if ($num == '000') $mils ++;
  56.       elseif ($mils != 0) {
  57.          if (isset($matmil[$sub])) $t .= ' ' . $matmil[$sub];
  58.          $mils = 0;
  59.       }
  60.       $neutro = true;
  61.       $tex = $t . $tex;
  62.    }
  63.    $tex = $neg . substr($tex, 1) . $fin;
  64.    return ucfirst($tex);
  65. }
  66. ?>
  #6 (permalink)  
Antiguo 30/04/2010, 11:37
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: necesito funcion que convierta numeros a letra

Lo mejor es que lo crees y que después lo des de aporte. No es educativo que alguien te cree la función y tu solo tengas que copiar y pegar sin analizar el código. Trata de hacerlo, así aprenderás a manejarte en PHP.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #7 (permalink)  
Antiguo 30/04/2010, 11:43
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: necesito funcion que convierta numeros a letra

pasa q es una emergencia, yo vivo estudiando php, pero ahora se me complica el tiempo y necesito ese codigo...y mis conocimientos actuales no permiten q lo modifique solo
  #8 (permalink)  
Antiguo 30/04/2010, 13:00
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: necesito funcion que convierta numeros a letra

Para que aprendas es mejor haciéndolo por su propia cuenta. Si es una asignación no es educativo que pidas que otro te haga el trabajo.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #9 (permalink)  
Antiguo 30/04/2010, 13:19
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: necesito funcion que convierta numeros a letra

bueno, hice una pero me da error con numeros 3,56
Código PHP:
Ver original
  1. <?php
  2. function centimos()
  3. {
  4.     global $importe_parcial;
  5.  
  6.     $importe_parcial = number_format($importe_parcial, 2, ".", "") * 100;
  7.  
  8.     if ($importe_parcial > 0)
  9.         $num_letra = " con ".decena_centimos($importe_parcial);
  10.     else
  11.         $num_letra = "";
  12.  
  13.     return $num_letra;
  14. }
  15.  
  16. function unidad_centimos($numero)
  17. {
  18.     switch ($numero)
  19.     {
  20.         case 9:
  21.         {
  22.             $num_letra = "nueve centavos";
  23.             break;
  24.         }
  25.         case 8:
  26.         {
  27.             $num_letra = "ocho centavos";
  28.             break;
  29.         }
  30.         case 7:
  31.         {
  32.             $num_letra = "siete centavos";
  33.             break;
  34.         }
  35.         case 6:
  36.         {
  37.             $num_letra = "seis centavos";
  38.             break;
  39.         }
  40.         case 5:
  41.         {
  42.             $num_letra = "cinco centavos";
  43.             break;
  44.         }
  45.         case 4:
  46.         {
  47.             $num_letra = "cuatro centavos";
  48.             break;
  49.         }
  50.         case 3:
  51.         {
  52.             $num_letra = "tres centavos";
  53.             break;
  54.         }
  55.         case 2:
  56.         {
  57.             $num_letra = "dos centavos";
  58.             break;
  59.         }
  60.         case 1:
  61.         {
  62.             $num_letra = "un centavo";
  63.             break;
  64.         }
  65.     }
  66.     return $num_letra;
  67. }
  68.  
  69. function decena_centimos($numero)
  70. {
  71.     if ($numero >= 10)
  72.     {
  73.         if ($numero >= 90 && $numero <= 99)
  74.         {
  75.               if ($numero == 90)
  76.                   return "noventa centavos";
  77.               else if ($numero == 91)
  78.                   return "noventa y un centavos";
  79.               else
  80.                   return "noventa y ".unidad_centimos($numero - 90);
  81.         }
  82.         if ($numero >= 80 && $numero <= 89)
  83.         {
  84.             if ($numero == 80)
  85.                 return "ochenta centavos";
  86.             else if ($numero == 81)
  87.                 return "ochenta y un centavos";
  88.             else
  89.                 return "ochenta y ".unidad_centimos($numero - 80);
  90.         }
  91.         if ($numero >= 70 && $numero <= 79)
  92.         {
  93.             if ($numero == 70)
  94.                 return "setenta centavos";
  95.             else if ($numero == 71)
  96.                 return "setenta y un centavos";
  97.             else
  98.                 return "setenta y ".unidad_centimos($numero - 70);
  99.         }
  100.         if ($numero >= 60 && $numero <= 69)
  101.         {
  102.             if ($numero == 60)
  103.                 return "sesenta centavos";
  104.             else if ($numero == 61)
  105.                 return "sesenta y un centavos";
  106.             else
  107.                 return "sesenta y ".unidad_centimos($numero - 60);
  108.         }
  109.         if ($numero >= 50 && $numero <= 59)
  110.         {
  111.             if ($numero == 50)
  112.                 return "cincuenta centavos";
  113.             else if ($numero == 51)
  114.                 return "cincuenta y un centavos";
  115.             else
  116.                 return "cincuenta y ".unidad_centimos($numero - 50);
  117.         }
  118.         if ($numero >= 40 && $numero <= 49)
  119.         {
  120.             if ($numero == 40)
  121.                 return "cuarenta centavos";
  122.             else if ($numero == 41)
  123.                 return "cuarenta y un centavos";
  124.             else
  125.                 return "cuarenta y ".unidad_centimos($numero - 40);
  126.         }
  127.         if ($numero >= 30 && $numero <= 39)
  128.         {
  129.             if ($numero == 30)
  130.                 return "treinta centavos";
  131.             else if ($numero == 31)
  132.                 return "treinta y un centavos";
  133.             else
  134.                 return "treinta y ".unidad_centimos($numero - 30);
  135.         }
  136.         if ($numero >= 20 && $numero <= 29)
  137.         {
  138.             if ($numero == 20)
  139.                 return "veinte centavos";
  140.             else if ($numero == 21)
  141.                 return "veintiun centavos";
  142.             else
  143.                 return "veinti".unidad_centimos($numero - 20);
  144.         }
  145.         if ($numero >= 10 && $numero <= 19)
  146.         {
  147.             if ($numero == 10)
  148.                 return "diez centavos";
  149.             else if ($numero == 11)
  150.                 return "once centavos";
  151.             else if ($numero == 12)
  152.                 return "doce centavos";
  153.             else if ($numero == 13)
  154.                 return "trece centavos";
  155.             else if ($numero == 14)
  156.                 return "catorce centavos";
  157.             else if ($numero == 15)
  158.                 return "quince centavos";
  159.             else if ($numero == 16)
  160.                 return "dieciseis centavos";
  161.             else if ($numero == 17)
  162.                 return "diecisiete centavos";
  163.             else if ($numero == 18)
  164.                 return "dieciocho centavos";
  165.             else if ($numero == 19)
  166.                 return "diecinueve centavos";
  167.         }
  168.     }
  169.     else
  170.         return unidad_centimos($numero);
  171. }
  172.  
  173. function unidad($numero)
  174. {
  175.     switch ($numero)
  176.     {
  177.         case 9:
  178.         {
  179.             $num = "nueve";
  180.             break;
  181.         }
  182.         case 8:
  183.         {
  184.             $num = "ocho";
  185.             break;
  186.         }
  187.         case 7:
  188.         {
  189.             $num = "siete";
  190.             break;
  191.         }
  192.         case 6:
  193.         {
  194.             $num = "seis";
  195.             break;
  196.         }
  197.         case 5:
  198.         {
  199.             $num = "cinco";
  200.             break;
  201.         }
  202.         case 4:
  203.         {
  204.             $num = "cuatro";
  205.             break;
  206.         }
  207.         case 3:
  208.         {
  209.             $num = "tres";
  210.             break;
  211.         }
  212.         case 2:
  213.         {
  214.             $num = "dos";
  215.             break;
  216.         }
  217.         case 1:
  218.         {
  219.             $num = "uno";
  220.             break;
  221.         }
  222.     }
  223.     return $num;
  224. }
  225.  
  226. function decena($numero)
  227. {
  228.     if ($numero >= 90 && $numero <= 99)
  229.     {
  230.         $num_letra = "noventa ";
  231.        
  232.         if ($numero > 90)
  233.             $num_letra = $num_letra."y ".unidad($numero - 90);
  234.     }
  235.     else if ($numero >= 80 && $numero <= 89)
  236.     {
  237.         $num_letra = "ochenta ";
  238.        
  239.         if ($numero > 80)
  240.             $num_letra = $num_letra."y ".unidad($numero - 80);
  241.     }
  242.     else if ($numero >= 70 && $numero <= 79)
  243.     {
  244.             $num_letra = "setenta ";
  245.        
  246.         if ($numero > 70)
  247.             $num_letra = $num_letra."y ".unidad($numero - 70);
  248.     }
  249.     else if ($numero >= 60 && $numero <= 69)
  250.     {
  251.         $num_letra = "sesenta ";
  252.        
  253.         if ($numero > 60)
  254.             $num_letra = $num_letra."y ".unidad($numero - 60);
  255.     }
  256.     else if ($numero >= 50 && $numero <= 59)
  257.     {
  258.         $num_letra = "cincuenta ";
  259.        
  260.         if ($numero > 50)
  261.             $num_letra = $num_letra."y ".unidad($numero - 50);
  262.     }
  263.     else if ($numero >= 40 && $numero <= 49)
  264.     {
  265.         $num_letra = "cuarenta ";
  266.        
  267.         if ($numero > 40)
  268.             $num_letra = $num_letra."y ".unidad($numero - 40);
  269.     }
  270.     else if ($numero >= 30 && $numero <= 39)
  271.     {
  272.         $num_letra = "treinta ";
  273.        
  274.         if ($numero > 30)
  275.             $num_letra = $num_letra."y ".unidad($numero - 30);
  #10 (permalink)  
Antiguo 30/04/2010, 13:19
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: necesito funcion que convierta numeros a letra

Código PHP:
Ver original
  1. }
  2.     else if ($numero >= 20 && $numero <= 29)
  3.     {
  4.         if ($numero == 20)
  5.             $num_letra = "veinte ";
  6.         else
  7.             $num_letra = "veinti".unidad($numero - 20);
  8.     }
  9.     else if ($numero >= 10 && $numero <= 19)
  10.     {
  11.         switch ($numero)
  12.         {
  13.             case 10:
  14.             {
  15.                 $num_letra = "diez ";
  16.                 break;
  17.             }
  18.             case 11:
  19.             {
  20.                 $num_letra = "once ";
  21.                 break;
  22.             }
  23.             case 12:
  24.             {
  25.                 $num_letra = "doce ";
  26.                 break;
  27.             }
  28.             case 13:
  29.             {
  30.                 $num_letra = "trece ";
  31.                 break;
  32.             }
  33.             case 14:
  34.             {
  35.                 $num_letra = "catorce ";
  36.                 break;
  37.             }
  38.             case 15:
  39.             {
  40.                 $num_letra = "quince ";
  41.                 break;
  42.             }
  43.             case 16:
  44.             {
  45.                 $num_letra = "dieciseis ";
  46.                 break;
  47.             }
  48.             case 17:
  49.             {
  50.                 $num_letra = "diecisiete ";
  51.                 break;
  52.             }
  53.             case 18:
  54.             {
  55.                 $num_letra = "dieciocho ";
  56.                 break;
  57.             }
  58.             case 19:
  59.             {
  60.                 $num_letra = "diecinueve ";
  61.                 break;
  62.             }
  63.         }
  64.     }
  65.     else
  66.         $num_letra = unidad($numero);
  67.  
  68.     return $num_letra;
  69. }
  70.  
  71. function centena($numero)
  72. {
  73.     if ($numero >= 100)
  74.     {
  75.         if ($numero >= 900 & $numero <= 999)
  76.         {
  77.             $num_letra = "novecientos ";
  78.            
  79.             if ($numero > 900)
  80.                 $num_letra = $num_letra.decena($numero - 900);
  81.         }
  82.         else if ($numero >= 800 && $numero <= 899)
  83.         {
  84.             $num_letra = "ochocientos ";
  85.            
  86.             if ($numero > 800)
  87.                 $num_letra = $num_letra.decena($numero - 800);
  88.         }
  89.         else if ($numero >= 700 && $numero <= 799)
  90.         {
  91.             $num_letra = "setecientos ";
  92.            
  93.             if ($numero > 700)
  94.                 $num_letra = $num_letra.decena($numero - 700);
  95.         }
  96.         else if ($numero >= 600 && $numero <= 699)
  97.         {
  98.             $num_letra = "seiscientos ";
  99.            
  100.             if ($numero > 600)
  101.                 $num_letra = $num_letra.decena($numero - 600);
  102.         }
  103.         else if ($numero >= 500 && $numero <= 599)
  104.         {
  105.             $num_letra = "quinientos ";
  106.            
  107.             if ($numero > 500)
  108.                 $num_letra = $num_letra.decena($numero - 500);
  109.         }
  110.         else if ($numero >= 400 && $numero <= 499)
  111.         {
  112.             $num_letra = "cuatrocientos ";
  113.            
  114.             if ($numero > 400)
  115.                 $num_letra = $num_letra.decena($numero - 400);
  116.         }
  117.         else if ($numero >= 300 && $numero <= 399)
  118.         {
  119.             $num_letra = "trescientos ";
  120.            
  121.             if ($numero > 300)
  122.                 $num_letra = $num_letra.decena($numero - 300);
  123.         }
  124.         else if ($numero >= 200 && $numero <= 299)
  125.         {
  126.             $num_letra = "doscientos ";
  127.            
  128.             if ($numero > 200)
  129.                 $num_letra = $num_letra.decena($numero - 200);
  130.         }
  131.         else if ($numero >= 100 && $numero <= 199)
  132.         {
  133.             if ($numero == 100)
  134.                 $num_letra = "cien ";
  135.             else
  136.                 $num_letra = "ciento ".decena($numero - 100);
  137.         }
  138.     }
  139.     else
  140.         $num_letra = decena($numero);
  141.    
  142.     return $num_letra;
  143. }
  144.  
  145. function cien()
  146. {
  147.     global $importe_parcial;
  148.    
  149.     $parcial = 0; $car = 0;
  150.    
  151.     while (substr($importe_parcial, 0, 1) == 0)
  152.         $importe_parcial = substr($importe_parcial, 1, strlen($importe_parcial) - 1);
  153.    
  154.     if ($importe_parcial >= 1 && $importe_parcial <= 9.99)
  155.         $car = 1;
  156.     else if ($importe_parcial >= 10 && $importe_parcial <= 99.99)
  157.         $car = 2;
  158.     else if ($importe_parcial >= 100 && $importe_parcial <= 999.99)
  159.         $car = 3;
  160.    
  161.     $parcial = substr($importe_parcial, 0, $car);
  162.     $importe_parcial = substr($importe_parcial, $car);
  163.    
  164.     $num_letra = centena($parcial).centimos();
  165.    
  166.     return $num_letra;
  167. }
  168.  
  169. function cien_mil()
  170. {
  171.     global $importe_parcial;
  172.    
  173.     $parcial = 0; $car = 0;
  174.    
  175.     while (substr($importe_parcial, 0, 1) == 0)
  176.         $importe_parcial = substr($importe_parcial, 1, strlen($importe_parcial) - 1);
  177.    
  178.     if ($importe_parcial >= 1000 && $importe_parcial <= 9999.99)
  179.         $car = 1;
  180.     else if ($importe_parcial >= 10000 && $importe_parcial <= 99999.99)
  181.         $car = 2;
  182.     else if ($importe_parcial >= 100000 && $importe_parcial <= 999999.99)
  183.         $car = 3;
  184.    
  185.     $parcial = substr($importe_parcial, 0, $car);
  186.     $importe_parcial = substr($importe_parcial, $car);
  187.    
  188.     if ($parcial > 0)
  189.     {
  190.         if ($parcial == 1)
  191.             $num_letra = "mil ";
  192.         else
  193.             $num_letra = centena($parcial)." mil ";
  194.     }
  195.    
  196.     return $num_letra;
  197. }
  198.  
  199.  
  200. function millon()
  201. {
  202.     global $importe_parcial;
  203.    
  204.     $parcial = 0; $car = 0;
  205.    
  206.     while (substr($importe_parcial, 0, 1) == 0)
  207.         $importe_parcial = substr($importe_parcial, 1, strlen($importe_parcial) - 1);
  208.    
  209.     if ($importe_parcial >= 1000000 && $importe_parcial <= 9999999.99)
  210.         $car = 1;
  211.     else if ($importe_parcial >= 10000000 && $importe_parcial <= 99999999.99)
  212.         $car = 2;
  213.     else if ($importe_parcial >= 100000000 && $importe_parcial <= 999999999.99)
  214.         $car = 3;
  215.    
  216.     $parcial = substr($importe_parcial, 0, $car);
  217.     $importe_parcial = substr($importe_parcial, $car);
  218.    
  219.     if ($parcial == 1)
  220.         $num_letras = "un millón ";
  221.     else
  222.         $num_letras = centena($parcial)." millones ";
  223.    
  224.     return $num_letras;
  225. }
  226.  
  227. function convertir_a_letras($numero)
  228. {
  229.     global $importe_parcial;
  230.    
  231.     $importe_parcial = $numero;
  232.    
  233.     if ($numero < 1000000000)
  234.     {
  235.         if ($numero >= 1000000 && $numero <= 999999999.99)
  236.             $num_letras = millon().cien_mil().cien();
  237.         else if ($numero >= 1000 && $numero <= 999999.99)
  238.             $num_letras = cien_mil().cien();
  239.         else if ($numero >= 1 && $numero <= 999.99)
  240.             $num_letras = cien();
  241.         else if ($numero >= 0.01 && $numero <= 0.99)
  242.         {
  243.             if ($numero == 0.01)
  244.                 $num_letras = "un centavo";
  245.             else
  246.                 $num_letras = convertir_a_letras(($numero * 100)."/100")." centavos";
  247.         }
  248.     }
  249.     return $num_letras;
  250. }
  251.  
  252. ?>

Etiquetas: funcion, letra, numeros
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:55.