Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/01/2010, 17:27
expecimen
 
Fecha de Ingreso: octubre-2006
Ubicación: Ciudad Ojeda, Venezuela
Mensajes: 123
Antigüedad: 17 años, 6 meses
Puntos: 0
No da el millon, billon ni millardo (SOLUCIONADO)

Hola de nuevo buscando un scritp para convertir de numeros a letras me consegui este escritp funciona muy bien me da los resultados en centimos de todo claro tenia algunos erros gramaticales pero ya se lo he idoa corrijiendo y por supuesto tuve que colocalo la denominacion de mi pais (nombre de la moneda)

Código:
38.56 Bs. = Treinta y Ocho Bolivares, con Veinte y Seis Centimos
pero haciendo las ultimas prueba veo que cuando llega a 2 millones da un error asi:

Código:
Fatal error: Call to undefined function unidades() in C:\AppServ\www\sedemat\prueba\numerosALetras.class.php  on line 114
y eso ocurre del 2 a 9 millones..... y ademas de que tampoco llega al billon o millardo :-p

aqui les dejos el codigo para ver si me pueden ayudar en donde esta el error por que la verdad no le consigo la vuelta , si tienen algun otro scritp mejor que este tambien me serviria:

Código PHP:
<?php
class numerosALetras{
/*
Script Name: *numerosAletras
Script URI: http://www.mis-algoritmos.com/2007/09/07/numbers_to_words/
Description: Permite convertir numeros a letras mediante el uso de una sencilla clase.
Script Version: 0.1
Author: Victor De la Rocha
Author URI: http://www.mis-algoritmos.com
*/
        
var $resultado;
        var 
$antes_con_despues='Bolivares, con';
        var 
$despues 'Centimos';
        var 
$antes_sin_despues='Bolivares.';
        
/*
            Constructor
        */
        
function numerosALetras($valor=''){
                if(
is_numeric($valor))
                    return 
$this->convertir($valor);
                return 
false;
            }
        
/*
            Retorna el valor de la centena que se le envie como parametro.
        */
        
function centenas($VCentena){
                
$valores = array('Cero','Ciento','Dos','Tres','Cuatro','Quiniento','Seis',
                
'Seteciento','Ocho','Noveciento','Diez','Once','Doce','Trece','Catorce',
                
'Quince',20=>'Veinte',30=>'Treinta',40=>'Cuarenta',50=>'Cincuenta',
                
60=>'Sesenta',70=>'Setenta',80=>'Ochenta',90=>'Noventa',100=>'Ciento',
                
500=>'Quinientos',700=>'Setecientos',900=>'Novecientos');
        
                switch(
$centenas){
                        case 
'1': return $valores[100]; break;
                        case 
'5': return $valores[500]; break;
                        case 
'7': return $valores[700]; break;
                        case 
'9': return $valores[900]; break;
                        default: return 
$valores[$VCentena];
                    }
            }
        
/*
            Retorna el valor de la unidad que se le envie como parametro.
        */
        
function unidades($unidad){
                
$valores = array('Cero','Uno','Dos','Tres','Cuatro','Cinco','Seis',
                
'Siete','Ocho','Nueve','Diez','Once','Doce','Trece','Catorce',
                
'Quince',20=>'Veinte',30=>'Treinta',40=>'Cuarenta',50=>'Cincuenta',
                
60=>'Sesenta',70=>'Setenta',80=>'Ochenta',90=>'Noventa',100=>'Ciento',
                
101=>'Quinientos',102=>'Setecientos',103=>'Novecientos'
                
);
            
                return 
$valores[$unidad];
            }
    
        
/*
            Retorna el valor de la decena que se le envie como parametro
        */
        
function decenas($decena){
                
$valores = array('Cero','Uno','Dos','Tres','Cuatro','Cinco','Seis','Siete',
                
'Ocho','Nueve','Diez','Once','Doce','Trece','Catorce','Quince',20=>'Veinte',30=>'Treinta',
                
40=>'Cuarenta',50=>'Cincuenta',60=>'Sesenta',70=>'Setenta',80=>'Ochenta',90=>'Noventa',
                
100=>'Ciento',101=>'Quinientos',102=>'Setecientos',103=>'Novecientos');
        
                return 
$valores[$decena];
            }
    
    
        function 
evalua($valor){
                if(
$valor==0)
                    return 
'cero';
                    
                
$decimales 0;
                
$letras '';
                while(
$valor!=0){
                        
// Validamos si supera los 100 millones
                        
if($valor>=1000000000)
                            return 
'L&iacute;mite de aplicaci&oacute;n exedido.';
                        
                        
//Centenas de Millón
                        
if (($valor<1000000000) and ($valor>=100000000)){
                                if ((
intval($valor/100000000)==1) and (($valor-(intval($valor/100000000)*100000000))<1000000))
                                        
$letras.=(string)'Cien Millones ';
                                    else{
                                        
$letras.=$this->centenas(intval($valor/100000000));
                                        If ((
intval($valor/100000000)<>1) and (intval($valor/100000000)<>5) and (intval($valor/100000000)<>7) and (intval($valor/100000000)<> 9))
                                                
$letras.=(string)'ciento ';
                                            else
                                                
$letras.=(string)' ';
                                    }
                                
$valor=$valor-(Intval($valor/100000000)*100000000);
                            }
            
                        
//Decenas de Millón
                        
if(($valor<100000000) and ($valor>=10000000)){
                                if(
intval($valor/1000000)<16){
                                        
$tempo=$this->decenas(intval($valor/1000000));
                                        
$letras.=(string)$tempo;
                                        
$letras.=(string)' Millones';
                                        
$valor=$valor-(intval($valor/1000000)*1000000);
                                    }else{
                                        
$letras.=$this->decenas(intval($valor/10000000)*10);
                                        
$valor=$valor-(intval($valor/10000000)*10000000);
                                        if (
$valor>1000000)
                                            
$letras.=$letras.' y ';
                                    }
                            }
            
                        
//Unidades de Millon
                        
if(($valor<10000000) and ($valor>=1000000)){
                                    
$tempo=(intval($valor/1000000));
                                    if(
$tempo==1)
                                            
$letras.=(string)' Un Mill&oacute;n ';
                                        else{
                                            
$tempounidades(intval($valor/1000000));
                                            
$letras.=(string)$tempo;
                                            
$letras.=(string)" Millones ";
                                        }
                                
$valor=$valor-(intval($valor/1000000)*1000000);
                            }
            
                        
//Centenas de Millar
                        
if(($valor<1000000) and ($valor>=100000)){
                                
$tempo=(intval($valor/100000));
                                
$tempo2=($valor-($tempo*100000));
                                if((
$tempo==1) and ($tempo2<1000))
                                        
$letras.=(string) 'cien mil ';
                                    else{
                                        
$tempo=$this->centenas(intval($valor/100000));
                                        
$letras.=(string)$tempo;
                                        
$tempo=(intval($valor/100000));
                                        if((
$tempo <> 1) and ($tempo <> 5) and ($tempo <> 7) and ($tempo <> 9))
                                                
$letras.=(string)'ciento ';
                                            else
                                                
$letras.=(string)' ';
                                    }
                                
$valor=$valor-(intval($valor/100000)*100000);
                            }
            
                        
//Decenas de Millar
                        
if(($valor<100000) and ($valor>=10000)){
                                
$tempo=(intval($valor/1000));
                                if(
$tempo<16){
                                        
$tempo=$this->decenas(intval($valor/1000));
                                        
$letras.=(string)$tempo;
                                        
$letras.=(string)' mil ';
                                        
$valor=$valor-(intval($valor/1000)*1000);
                                    }else{
                                        
$tempo=$this->decenas(intval($valor/10000)*10);
                                        
$letras.=(string) $tempo;
                                        
$valor=$valor-(intval(($valor/10000))*10000);
                                        if(
$valor>1000)
                                                
$letras.=(string)' y ';
                                            else
                                                
$letras.=(string)' mil ';
                                    }
                            }
            
            
                        
//Unidades de Millar
                        
if(($valor<10000) and ($valor>=1000)){
                                
$tempo=intval($valor/1000);
                                if(
$tempo==1)
                                    
$letras.=(string)'';//'un';
                                    
else{
                                        
$tempo=$this->unidades(intval($valor/1000));
                                        
$letras.=(string) $tempo;
                                    }
                                
$letras.=(string)' mil ';
                                
$valor=$valor-(intval($valor/1000)*1000);
                            }
            
                        
//Centenas
                        
if(($valor<1000) and ($valor>99)){
                                if ((
intval($valor/100)==1) and (($valor-(intval($valor/100)*100))<1))
                                        
$letras.='cien ';
                                    else{
                                        
$temp=(intval($valor/100));
                                        
$l2=$this->centenas($temp);
                                        
$letras.=(string) $l2;
                                        if((
intval($valor/100)<>1) and (intval($valor/100)<>5) and (intval($valor/100)<>7) and (intval($valor/100)<>9))
                                                
$letras.='ciento ';
                                            else
                                                
$letras.=(string)' ';
                                    }
                                
$valor=$valor-(intval($valor/100)*100);
                            }
            
                        
//Decenas
                        
if(($valor<100) and ($valor>9)){
                                if(
$valor<16){
                                        
$tempo=$this->decenas(intval($valor));
                                        
$letras.=$tempo;
                                        
$Numer =$valor-Intval($valor);
                                    }else{
                                        
$tempo=$this->decenas(Intval(($valor/10))*10);
                                        
$letras.=(string)$tempo;
                                        
$valor=$valor-(Intval(($valor/10))*10);
                                        if(
$valor>0.99)
                                            
$letras.=(string)' y ';
                                    }
                            }
            
                        
//Unidades
                        
if(($valor<10) And ($valor>0.99)){
                                
$tempo=$this->unidades(intval($valor));
                                
$letras.=(string)$tempo;
                                
$valor=$valor-intval($valor);
                            }
            
                        
//Decimales
                        
if($decimales<=0)
                            if((
$letras <> "Error en Conversi&oacute;n a Letras") and (strlen(trim($letras))>0))
                                
$letras .= (string) ' ';
                    return 
$letras;
                }
            }
        
/*
            Retorna el texto de el numero enviado como parametros
        */
        
function convertir($valor){
                
ob_start();
                
$tt $valor;
                
$valor intval($tt);
                
$decimales $tt intval($tt);
                
                
$decimales substr($decimales,strpos($decimales,'.'),4)*(100); // con 4 posiciones obtiene hasta los centavos (de centavos)p ej "21.9", con 3 obtiene "21"
                
$decimalesround($decimales);

                
//Parte entera
                
print $this->evalua($valor);
                
                
//Parte Decimal
                
if($decimales){
                        print 
" $this->antes_con_despues ";
                        print 
$this->evalua($decimales);
                        print 
" $this->despues";
                    }else{
                        print 
" $this->antes_sin_despues ";
                    }
                return 
$this->resultado $texto ob_get_clean();
            }
    }
?>

Última edición por expecimen; 26/01/2010 a las 21:43