Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Numbers in spanish plain text

Title: Numbers in spanish plain text Question: Convert numbers to plain text (for check orders, by example) Answer: procedure TForm1.Button1Click(Sender: TObject); function xIntToLletras(Numero:LongInt):String; function xxIntToLletras(Valor:LongInt):String; const aUnidad : array[1..15] of String = ('UN','DOS','TRES','CUATRO','CINCO','SEIS', 'SIETE','OCHO','NUEVE','DIEZ','ONCE','DOCE', 'TRECE','CATORCE','QUINCE'); aCentena: array[1..9] of String = ('CIENTO','DOSCIENTOS','TRESCIENTOS', 'CUATROCIENTOS','QUINIENTOS','SEISCIENTOS', 'SETECIENTOS','OCHOCIENTOS','NOVECIENTOS'); aDecena : array[1..9] of String = ('DIECI','VEINTI','TREINTA','CUARENTA','CINCUENTA', 'SESENTA','SETENTA','OCHENTA','NOVENTA'); var Centena, Decena, Unidad, Doble: LongInt; Linea: String; begin if valor=100 then Linea:=' CIEN ' else begin Linea:=''; Centena := Valor div 100; Doble := Valor - (Centena*100); Decena := (Valor div 10) - (Centena*10); Unidad := Valor - (Decena*10) - (Centena*100); if Centena0 then Linea := Linea + Acentena[centena]+' '; if Doble0 then begin if Doble=20 then Linea := Linea +' VEINTE ' else begin if doble16 then Linea := Linea + aUnidad[Doble] else begin Linea := Linea +' '+ Adecena[Decena]; if (Decena2) and (Unidad0) then Linea := Linea+' Y '; if Unidad0 then Linea := Linea + aUnidad[Unidad]; end; end; end; end; Result := Linea; end; var Millones,Miles,Unidades: Longint; Linea : String; begin {Inicializamos el string que contendr las letras segn el valor numrico} if numero=0 then Linea := 'CERO' else if numero0 then Linea := 'MENOS ' else if numero=1 then begin Linea := 'UN'; xIntToLletras := Linea; exit end else if numero1 then Linea := ''; {Determinamos el N de millones, miles y unidades de numero en positivo} Numero := Abs(Numero); Millones := numero div 1000000; Miles := (numero - (Millones*1000000)) div 1000; Unidades := numero - ((Millones*1000000)+(Miles*1000)); {Vamos poniendo en el string las cadenas de los nmeros(llamando a subfuncion)} if Millones=1 then Linea:= Linea + ' UN MILLON ' else if Millones1 then Linea := Linea + xxIntToLletras(Millones) + ' MILLONES '; if Miles =1 then Linea:= Linea + ' MIL ' else if Miles1 then Linea := Linea + xxIntToLletras(Miles)+ ' MIL '; if Unidades 0 then Linea := Linea + xxIntToLletras(Unidades); xIntToLletras := Linea; end; begin Label1.Caption:= xIntToLletras(StrToInt(Edit1.Text)); end;