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 % 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 == 0 && !$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($miles, false) . "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($millo, false) . "MILLONES ";
if ($units > 0) $r .= seisnumeros($units, true);
return $r;
}
function desglosar( $numerodec ) {
$patron = ".";
$posicion = strpos($numerodec,$patron);
$decimales= substr($numerodec,$posicion + 1 ,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 :)