Sephiroth
http://sephiroth.scifi-action.de/board/

$zahl2wort() & $num2word()
http://sephiroth.scifi-action.de/board/viewtopic.php?f=4&t=76
Seite 1 von 1

Autor:  Sephiroth [ 8. Juni 2008 12:52 ]
Betreff des Beitrags:  $zahl2wort() & $num2word()

; Benutzung $zahl2wort(Zahl [max 114 stellig])
alias zahl2wort {
  !var %nums = TausendMi!Mi.Bi!Bi.Tri!Tri. $+ $&
    Quadri!Quadri.Quinti!Quinti.Sexti!Sexti. $+ $&
    Septi!Septi.Okti!Okti.Noni!Noni. $+ $&
    Dezi!Dezi.Undezi!Undezi.Duodezi!Duodezi. $+ $&
    Tredezi!Tredezi.Quattuordezi!Quattuordezi.Quindezi!Quindezi. $+ $&
    Sexdezi!Sexdezi.Septendezi!Septendezi.Oktodezi!Oktodezi.
  !var %o,%s,%i $remove($1,$chr(44)),%r !return,%1,%2,%3,%4,%x
  !var %zig = 0ZwanzigDreißigVierzigFünfzigSechzigSiebzigAchtzigNeunzig
  if (!$regex(%i,/^(?=\S*\d)(\d{0,114}|0*)(\.\d*)?($| )/)) %r $iif(%i != %o,Ungültig)
  while (%i) {
    %x = $replace($¼($mid(%i,-3,1),hundert),_,) | %1 = $replace($iif(%s,$gettok(%nums,%s,2)),!,llion,.,llarde) | %2 = $mid(%i,-2) | %3 = $¼($int(%2)) | %4 = $iif(%2 > 19,$¼($mid(%i,-1)) $+ $iif(%2 > 19 && $right(%2,1) != 0,-) $+ $gettok(%zig,$mid(%i,-2,1),2)))
    %x = %x $iif(%2 < 20,$iif(%3 == Ein && !%s,Eins,%3)) $+ $iif(%s > 1 && %3 == Ein,e) $upper($left(%4,1)) $+ $lower($right(%4,-1)) $iif($int($mid(%i,-3)) != 0,$iif(%3 != Ein && %s > 1,$»(%1),%1))
    %o = %x %o | %i = $left(%i,-3) | inc %s
  }
  return $iif(%o,$replace(%o,+,ehn,-,und),Null)
}
alias -l » if ($1) return $1 $+ $iif($right($1,1) == e,n,en)
alias -l ¼ if ($1) return $gettok(EinZweiDreiVierFünfSechsSiebenAchtNeunZ+ElfZwölfDreiz+Vierz+Fünfz+Sechsz+Siebz+Achtz+Neunz+,$1,2) $+ $2

Autor:  Sephiroth [ 8. Juni 2008 13:01 ]
Betreff des Beitrags:  $zahl2wort() & $num2word()

; $num2word(number [max 66 digits])
alias -l ½ if ($1) return $3 $+ $gettok(OneTwoThreeFourFiveSixS7EightNineTenEl7TwelveThir+Four+Fif+Six+S7+Eigh+Nine+,$1,2) $2
alias num2word {
  var %o,%s,%i $remove($1,$chr(44)),%r return
  if (!$regex(%i,/^(?=\S*\d)(\d{0,66}|0*)(\.\d*)?($| )/)) %r $iif(%i != %o,Invalid)
  %i = 0 $+ $regml(1)
  while %i {
    %x = $½($mid(%i,-3,1),Hundred) $iif($mid(%i,-2) < 20,$½($int($ifmatch)),$+($½($calc($mid(%i,-2,1) -10)),ty,$½($mid(%i,-1),,-)))
    %o = %x $iif(%x && %s,$gettok(ThousandM.B.Tr.Quadr.Quint.Sext.Sept.Oct.Non.!Un!Duo!Tre!Quattuor!Quin!Sex!Septen!Octo!Novem!Vigint.,%s,2)) %o
    %i = $left(%i,-3)
    inc %s
  }
  %r $iif(%o,$replace(%o,7,even,+t,t,lvet,nt,urt,rt,!,dec.,.,illion,+,teen),Zero)
}

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/