|    
			
				10/08/2013, 20:58
			
			
			  | 
  |   |  |  |  Fecha de Ingreso: octubre-2010 Ubicación: Mexico 
						Mensajes: 3
					 Antigüedad: 15 años Puntos: 0 |  | 
  |  Monto en letra C++  
  Hola a todos, tengo un problema con un codigo que imprime una cantidad en este caso un monto en letra solo lo puedo hacer con enteros y quisiera hacerlo con decimales alguna idea de entrada este es el codigo solo quiero que me lea  
por ejemplo 1234.56 = Mil doscientos treinta y cuatro pesos con cincuenta y seis centavos. 
No he encontrado una funcion que me permita leer decimales y/o algun codigo que diga como los lee por ejemplo como saber despues del punto que numeros hay o algo por el estilo. 
Alguna idea o tip, de antemano muchas gracias.    
Código:
  #include <iostream.h>
#include<conio.h>
#include<stdio.h>
#include <stdlib.h>
void unidades_en_letra (unsigned long cantidad);
void millares_en_letra (unsigned long cantidad);
void millones_en_letra (unsigned long cantidad);
int main(){
char Nom[20];
char RFC[15];
char Dom[30];
char muni[30];
unsigned long cantidad;
int  imp, iva, sub, hrs, ph, t, Retiva, Retisr,TL;
cout<<"\t Mi empresa S.A. De C.V \n";
cout<<"\t .......................... \n";
cout<<"Dame tu Nombre:\n";       
fgets(Nom,20,stdin);
cout<<"Dame tu RFC:\n";
fgets(RFC,15,stdin); 
cout<<"Dame tu Domicilio:\n";
fgets(Dom,30,stdin);
cout<<"Dame tu Municipio:\n";       
fgets(muni,30,stdin);
     
cout<<"¿Cuantas Horas Trabajaste?\n";
cin>>hrs;
cout<<"¿Caul es tu Pago por Hora? \n";
cin>>ph;
imp=hrs*ph;
iva=imp*.16;
sub=imp+iva;
Retiva=imp*.10;
Retisr=imp*.10;
cantidad=((sub-Retiva)-Retisr);
cout<<"Tu Importe es: \n"<<imp<<endl;
cout<<"Tu IVA es: \n"<<iva<<endl;
cout<<"Tu SubTotal es: \n"<<sub<<endl;
cout<<"Tu Retencion de IVA es: \n"<<Retiva<<endl;
cout<<"Tu Retencion De ISR es \n"<<Retisr<<endl;
cout<<"Total es: \n"<<cantidad;
	cout<<endl;
	millones_en_letra(cantidad);
	cout<<endl<<endl;
}
const char *unidades[] = {NULL, "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve"};
const char *decimas[] = {NULL, "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa"};
const char *diez_y[] = {NULL, "once", "doce", "trece", "catorce", "quince"};
const char *centenas[] = {NULL, "ciento", NULL, NULL, NULL, "quinientos", NULL, "setecientos", NULL, "novecientos"};
void unidades_en_letra (unsigned long cantidad){
	unsigned char unidad = cantidad % 10;
	unsigned char decima = (cantidad / 10) % 10;
	unsigned char centena = (cantidad / 100) % 10;
	if(centena!=0)
		if (centenas[centena]==0)
			cout<<unidades[centena]<< "cientos";
		else if (centena!=1 || unidad!=0 || decima!=0)
			cout<<centenas[centena];
		else
			cout<<"cien";
	if (unidad!=0 || decima!=0){
		if(centena!=0)
		cout<< " ";
		if (decima==0)
		cout<<unidades[unidad];
		else if (unidad==0)
		cout<<decimas[decima];
		else if (decima==1 && unidad>=1 && unidad <=5)
		cout<<diez_y[unidad];
		else if(decima==1)
		cout<<"veinti"<<unidades[unidad];
		else
		cout<< decimas[decima] <<" y "<< unidades[unidad];
	}
}
void millares_en_letra (unsigned long cantidad){
	unsigned long unidades = cantidad % 1000;
	unsigned long miles = (cantidad / 1000) % 1000;
	if (miles>1)
		unidades_en_letra (miles);
	if (miles!=0)
		cout<< "mil";
	if (unidades!=0 && miles!=0)
		cout<<" ";
	unidades_en_letra (unidades);
}
void millones_en_letra (unsigned long cantidad){
	unsigned long unidades = cantidad % 1000000;
	unsigned long millares = (cantidad / 1000000) % 1000000;
	if (millares>1){
		millares_en_letra(millares);
		cout<<" millones";
	}
	else if (millares!=0)
		cout<<" un millon";
	if (unidades!=0 && millares !=0)
		cout<<" ";
	millares_en_letra (unidades);
}
Otra pregunta si es posible convertir esta funcion de PHP a C++??    Código PHP:   
 <?
/*
 * PHP Freaks Code Library
 * http://www.phpfreaks.com/quickcode.php
 *
 * Title: Convert a number to words in spanish
 * Version: 1.0
 * Author: Alejandro Ordiales aka(alejandro)
 * Date: Thursday, 08/05/2004 - 09:20 PM
 *
 *
 *
 * NOTICE: This code is available from PHPFreaks.com code Library.
 *         This code is not Copyrighted by PHP Freaks.
 *
 *         PHP Freaks does not claim authorship of this code.
 *
 *         This code was submitted to our website by a user.
 *
 *         The user may or may not claim authorship of this code.
 *
 *         If there are any questions about the origin of this code,
 *         please contact the person who submitted it, not PHPFreaks.com!
 *
 *         USE THIS CODE AT YOUR OWN RISK! NO GUARANTEES ARE GIVEN!
 *
 * SHAMELESS PLUG: Need WebHosting? Checkout WebHost Freaks:
 *                 http://www.webhostfreaks.com
 *                 WebHosting by PHP Freaks / The Web Freaks!
 */
 
 
 // *    Description / Example:
 // *
 // *    This function returns a string in spanish from a numeric value. Just pass a  float number like 34565.78 and will return the string  (TREINTA Y CUATRO MIL QUINIENTOS SESENTA Y CINCO PESOS 78/100).
 // *    Based on the code written by Wayne Herbert.
 
 ?>
 
 <?
 // Title: Numeric to spanish words
 // Author: Wayne Herbert Modified by Alejandro Ordiales.
 // ** Thank you Wayne **
 // Date: Aug 05, 2004
 
 
 // Code Snipplet:
 
 //***************************************************************
 // this function converts an amount into alpha words in spanish
 // the mexican way.  Pass it a float.
 // Example:  $123.77 = (CIENTO VEINTITRES PESOS 77/100)
 // works up to 999,999,999.99 - Great for checks
 // Modify lines 69 and 73 to use other currency (pesos)
 //***************************************************************
 //***************************************************************
 // Esta funcion convierte una cantidad a letras en español
 // como lo hacemos en mexico.  Pasa un numero con o sin decimales
 // Ejemplo:  $123.77 = (CIENTO VEINTITRES PESOS 77/100)
 // funciona desde 1 hasta 999,999,999.99 - Util para cheques o
 // tiendas virtuales. Modifica las lineas 69 and 73 para usar
 // otra moneda
 //***************************************************************
 
 function makewords($numval)
 {
 $moneystr = "**"; // Variables Iniciales
 // Millions
 $milval = (integer)($numval / 1000000);
 if($milval == 1) {
 $moneystr .= "Un millon";
 }
 if($milval > 1) {
 $moneystr .= getwords($milval) . " millones";
 }
 // thousands
 $workval = $numval - ($milval * 1000000); // get rid of millions
 $thouval = (integer)($workval / 1000);
 if($thouval > 0) {
 $workword = getwords($thouval);
 if ($moneystr == "") {
 $moneystr = $workword . " mil";
 } else {
 $moneystr .= " " . $workword . " mil";
 }
 }
 // handle all the rest of the money
 $workval = $workval - ($thouval * 1000); // get rid of thousands
 $tensval = (integer)($workval);
 if ($moneystr == 0) {
 if ($tensval > 0) {
 $moneystr .= getwords($tensval);
 } else {
 $moneystr .= " ";//Cero
 }
 } else {
 // non zero values in hundreds and up
 $workword = getwords($tensval);
 $moneystr .= " " . $workword;
 }
 // plural or singular
 $workval = (integer)($numval);
 if ($workval == 1) {
 $moneystr .= " Con ";
 } else {
 $moneystr .= " Con ";
 }
 // do the pennies - use printf so that we get the
 // same rounding as printf
 $workstr = sprintf("%3.2f",$numval); // convert to a string
 $intstr = substr($workstr,strlen - 2, 2);
 $workint = (integer)($intstr);
 if ($workint == 0)
 {
 $moneystr .= "00/100 **";
 } else {
 $moneystr .= $workint."/100 **";
 }
 
 // done - let's get out of here!
 return $moneystr;
 }
 
 //*************************************************************
 // this function creates word phrases in the range of 1 to 999.
 // pass it an integer value
 //*************************************************************
 function getwords($workval) {
 $numwords = array(
 1 => "un",
 2 => "dos",
 3 => "tres",
 4 => "cuatro",
 5 => "cinco",
 6 => "seis",
 7 => "siete",
 8 => "ocho",
 9 => "nueve",
 10 => "diez",
 11 => "once",
 12 => "doce",
 13 => "trece",
 14 => "catorce",
 15 => "quince",
 16 => "dieciseis",
 17 => "diecisiete",
 18 => "dieciocho",
 19 => "diecinueve",
 20 => "veinte",
 30 => "treinta",
 40 => "cuarenta",
 50 => "cincuenta",
 60 => "sesenta",
 70 => "setenta",
 80 => "ochenta",
 90 => "noventa");
 
 $numpal = array(
 1 => "ciento",
 2 => "doscientos",
 3 => "trescientos",
 4 => "cuatrocientos",
 5 => "quinientos",
 6 => "seiscientos",
 7 => "setecientos",
 8 => "ochocientos",
 9 => "novecientos");
 
 // handle the 100's
 $hundval2 = ($workval / 100); //if hundval ==1 and hundval2 > 1 {$retstr = "cien"}
 $retstr = " ";
 $hundval = (integer)($workval / 100);
 if ($hundval == 1 && $hundval2 == 1) {
 $retstr = "cien";
 }
 if ($hundval == 1 && $hundval2 > 1) {
 $retstr = "ciento";
 }
 if ($hundval > 1) {
 $retstr .= $numpal[$hundval];
 }
 
 // handle units and teens
 $workstr = "";
 $tensval = $workval - ($hundval * 100); // dump the 100's
 $tempval = ((integer)($tensval / 10)) * 10;
 $unitval = $tensval - $tempval;
 if (($tensval < 20) && ($tensval > 0)) {// do the teens
 $workstr = $numwords[$tensval];
 } else {// got to break out the units and tens
 if ($tensval > 20 && $tensval < 30) {// do the teens
 $workstr .= " veinti".$numwords[$unitval];
 } else {
 $workstr = $numwords[$tempval]; // get the tens
 if ($unitval > 0) {
 $workstr .= " y " . $numwords[$unitval];
 }
 }
 }
 // join all the parts together and leave
 if ($workstr != "") {
 if ($retstr != "") {
 $retstr .= " " . $workstr;
 } else {
 $retstr = $workstr;
 }
 } return $retstr;
 }
 
 /* #Esta parte del codigo es para que inicie la conversion.
 $valor = 225859;
 echo "Valor a Convertir: ".$valor."<br>";
 $resultado = makewords($valor);
 echo strtoupper($resultado);
 */
 ?>
    |