Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php pesos en letras rutina

<?php
function basico($numero) {
$valor = array ('uno','dos','tres','cuatro','cinco','seis','siete','ocho',
'nueve','diez','once','doce','trece','catorce','quince','dieciseis','diecisiete','dieciocho','diecinueve','veinte','veintiuno ','vientidos ','veintitrés ', 'veinticuatro','veinticinco',
'veintiséis','veintisiete','veintiocho','veintinueve');
return $valor[$numero - 1];
}

function decenas($n) {
$decenas = array (30=>'treinta',40=>'cuarenta',50=>'cincuenta',60=>'sesenta',
70=>'setenta',80=>'ochenta',90=>'noventa');
if( $n <= 29) return basico($n);
$x = $n % 10;
if ( $x == 0 ) {
return $decenas[$n];
} else return $decenas[$n - $x].' y '. basico($x);
}

function centenas($n) {
$cientos = array (100 =>'cien',200 =>'doscientos',300=>'trecientos',
400=>'cuatrocientos', 500=>'quinientos',600=>'seiscientos',
700=>'setecientos',800=>'ochocientos', 900 =>'novecientos');
if( $n >= 100) {
if ( $n % 100 == 0 ) {
return $cientos[$n];
} else {
$u = (int) substr($n,0,1);
$d = (int) substr($n,1,2);
return (($u == 1)?'ciento':$cientos[$u*100]).' '.decenas($d);
}
} else return decenas($n);
}

function miles($n) {
if($n > 999) {
if( $n == 1000) {return 'mil';}
else {
$l = strlen($n);
$c = (int)substr($n,0,$l-3);
$x = (int)substr($n,-3);
if($c == 1) {$cadena = 'mil '.centenas($x);}
else if($x != 0) {$cadena = centenas($c).' mil '.centenas($x);}
else $cadena = centenas($c). ' mil';
return $cadena;
}
} else return centenas($n);
}

function millones($n) {
if($n == 1000000) {return 'un millón';}
else {
$l = strlen($n);
$c = (int)substr($n,0,$l-6);
$x = (int)substr($n,-6);
if($c == 1) {
$cadena = ' millón ';
} else {
$cadena = ' millones ';
}
return miles($c).$cadena.(($x > 0)?miles($x):'');
}
}
function convertir($n) {
switch (true) {
case ( $n >= 1 && $n <= 29) : return basico($n); break;
case ( $n >= 30 && $n < 100) : return decenas($n); break;
case ( $n >= 100 && $n < 1000) : return centenas($n); break;
case ($n >= 1000 && $n <= 999999): return miles($n); break;
case ($n >= 1000000): return millones($n);
}
}

$html ='';
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$html = "
<p class='centrado'>".$_POST['numero'].' se escribe ';
$html.= '<b>'.ucfirst(convertir($_POST['numero'])).'</b>
';
echo $html;
}
?>
<form action="" method="post">
<input type="text" name="numero">
<button>Enviar</button>
</form>
Comment

PREVIOUS NEXT
Code Example
Php :: how to import csv into database in laravel 
Php :: multible many routes same controller 
Php :: laravel faker car plate br 
Php :: php objects 
Php :: laravel artisan helper function 
Php :: next previous post link 
Php :: array fill key use in php project 
Php :: Collapse all codes in PHP Storm IntelliJ 
Php :: php if form fails keep data 
Php :: Access directory above php 
Php :: php deader deny iframe 
Php :: Yii2: Setting default values for all attributes of a model 
Php :: php decrement variable 
Php :: get product by author id 
Php :: wordpress custom end point 
Php :: woocommerce_continue_shopping_redirect 
Php :: laravel change error page to open in vscode 
Php :: wordpress add sitemap.xml to robots.txt dynamically 
Php :: how do i implement blockchain payments on laravel website 
Php :: carbon 
Php :: Multiple databases user validation in Laravel 
Php :: how to share count of things to sidebar in laravel 
Php :: how to type casting and overriding in php 
Php :: php calculate age as float 
Php :: itop cron.php 
Php :: php array_diff vs array_diff_assoc 
Php :: what is WP_USE_THEMES 
Php :: curl_setopt timeout php 
Php :: php input seperated by space 
Php :: nested attributes - PHP 8.1 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =