MySQL Forums
Forum List  »  Spanish

Re: Funcion Numero a Letras
Posted by: Joaquín Alcañiz
Date: August 09, 2007 02:00AM

Hola,
Yo utilizo este pequeño procedimiento escrito en Basic (PureBasic),
Es muy sencillo de entender,y de traducir a cualquier otro lenguage, quizá la única operación especial es "%", que significa "tomar el resto de la división":


macro zmover_texto(tx)
  for n=1 to n+1
    if len(StringField(tx,n,"-"))=0: break
    else: zsalida + StringField(tx,n,"-")
          if zmaxl AND len(zsalida) > zmaxl AND FindString(zsalida,"-",1)=0
            zsalida + "-": endif
    endif
  next
  if right(zsalida,1) <> "-": zsalida +" ": endif
endmacro

macro zmover_grupo
  if znum3 = 100: zmover_texto("CIEN")
  else
    zcen = znum3 / 100
    zdec = znum3 % 100
    zuni = znum3 % 10
    if zcen <> 0:   zmover_texto(StringField(zcenten,zcen," ")): endif
    if zdec
      if zdec < 30: zmover_texto(StringField(zunidad,zdec," "))
      else
        zdec = zdec / 10
        if zdec:      zmover_texto(StringField(zdecena,zdec," ")): endif
        if zuni <> 0: zmover_texto("Y "+StringField(zunidad,zuni," ")): endif
      endif
    endif
  endif
endmacro


Procedure.s zNum2Text(zTot.l, zmaxl.l)
  zunidad.s: zdecena.s: zcenten.s
  zunidad = "UN DOS TRES CUATRO CINCO SEIS SIETE OCHO NUEVE DIEZ ONCE DOCE TRECE CATOR-CE QUINCE DIECI-SEIS DIECI-SIETE DIECI-OCHO DIECI-NUEVE VEINTE VEIN-TIUN VEIN-TIDOS VEIN-TITRES VEIN-TI-CUATRO VEIN-TI-CINCO VEIN-TISEIS VEIN-TI-SIETE VEIN-TIOCHO VEIN-TI-NUEVE"
  zdecena = "DIEZ VEINTE TREIN-TA CUA-RENTA CIN-CUENTA SESEN-TA SETEN-TA OCHEN-TA NOVEN-TA"
  zcenten = "CIENTO DOS-CIEN-TOS TRES-CIEN-TOS CUA-TRO-CIEN-TOS QUI-NIEN-TOS SEIS-CIEN-TOS SETE-CIEN-TOS OCHO-CIEN-TOS NOVE-CIEN-TOS"

  if zTot < 0: zTot = -zTot: endif
  zsalida.s = ""
  ztotent = ztot / 100
  ztotdec = ztot % 100

; los millones
  znum3 = ztotent / 1000000
  if znum3 = 1: zmover_texto("UN MILLON"): endif
  if znum3 > 1: zmover_grupo: zmover_texto("MILLONES"): endif

; los miles
  znum3 = ztotent % 1000000
  znum3 = znum3   / 1000
  if znum3 = 1: zmover_texto("MIL"): endif
  if znum3 > 1: zmover_grupo: zmover_texto("MIL"): endif

; las unidades
  znum3 = ztotent % 1000
  zmover_grupo

; los decimales
  if ztotdec
    zmover_texto("EUROS CON")
    znum3 = ztotdec
    zmover_grupo
    zmover_texto("CTS.")
  endif
  ProcedureReturn zsalida
EndProcedure


Options: ReplyQuote


Subject
Views
Written By
Posted
8099
August 03, 2007 12:26PM
Re: Funcion Numero a Letras
5909
August 09, 2007 02:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.