Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Alias NumConv {

Var %T = $Replace(Thousand M!B!Tr!Quadr!Quint!Sext!Sept!Oct!Non!"!Un"!Duo"!Tre


"!Quattuor"!Quin"!Sex"!Septen"!Octo"!Novem"!Vigint!,!,illion $+ $Chr(32),",dec),
%x = $g($Remove($1,$Chr(44)),1,32),%r = Return,%i,%k,%n,%s
If (%x != $null) {
If ($Pos(%x,.) = 1) || ($Count(%x,.) > 1) {
If ($I($Right(%x,-1))) %r Zero
%r Invalid
}
%k = $G(%x,2,46)
If (!%k) || ($I(%k,1)) %x = $G(%x,1,46)
%k = $Len(%x)
If (%k <= 66) && ($I(%x)) {
If (%k <= 3) || (!%x) %r $X(%x)
%i = 1
While (%i < %k) {
%n = $Right(%x,3)
if (%n > 0) %s = $X(%n) $Iif(%i > 1,$G(%T,$Calc(%i / 3),32)) %s
%x = $Left(%x,-3)
Inc %i 3
}
If (%x) %s = $X(%x) $G(%T,$calc(%i / 3),32) %s
%r %s
}
%r Invalid
}
}
Alias X {
Var %r = Return,%c = $Right($1,1),%b = $Mid($1,-2,1),%a = $Mid($1,-3,1),%T = $
Replace(One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thir! Fou
r! Fif! Six! Seven! Eigh! Nine!,!,teen),%Y = X Twenty Thirty Forty Fifty Sixty S
eventy Eighty Ninety Hundred,%s
If (%a) %s = $G(%T,%a,32) Hundred
If (%b) {
If (%b = 1) %r %s $G(%T,%b $+ %c,32)
%r %s $G(%Y,%b,32) $+ $Iif(%c,$+(-,$G(%T,%c,32)))
}
If (%c) %r %s $G(%T,%c,32)
If (%a) %r %s
%r Zero
}
Alias G Return $GetTok($1,$2,$3)
Alias I If ($1 IsNum) && ($left($1,1) IsNum) Return 1

You might also like