Código:
pero haciendo las ultimas prueba veo que cuando llega a 2 millones da un error asi:38.56 Bs. = Treinta y Ocho Bolivares, con Veinte y Seis Centimos
Código:
y eso ocurre del 2 a 9 millones..... y ademas de que tampoco llega al billon o millardo :-pFatal error: Call to undefined function unidades() in C:\AppServ\www\sedemat\prueba\numerosALetras.class.php on line 114
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ímite de aplicació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ón ';
else{
$tempo= unidades(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ó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"
$decimales= round($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();
}
}
?>