|
|
|
It is currently Thu Sep 09, 2010 3:11 pm
|
View unanswered posts | View active topics
|
Page 1 of 1
|
[ 5 posts ] |
|
| Author |
Message |
|
Scott`
|
Post subject: $numbertoword Posted: Tue Jul 28, 2009 6:23 am |
|
| User |
 |
Joined: Fri Apr 20, 2007 9:36 am Posts: 977 Location: NZ
|
A wee alias I made a while ago with Kyle|Mr_K_13 who helped me with coming up with the method. I left it unshortened to make it easier to edit and because I didn't have time. Code: /* NumberToWord created by StealthArcher To use: //echo $NumberToWord(<number>) Numbers may be as high as 999,999,999 (nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine). Any numbers higher than this can cause bad results because I didn't code billions into it. E.g. $NumberToWord(10) > ten $NumberToWord(1000) > one thousand $NumberToWord(687) > six hundred eighty seven */
alias -l DigitToWord { if ($1 == 0) return return $gettok(one two three four five six seven eight nine,$1,32) } alias -l TwoDigitsToWord { if ($1 == 0) return if ($1 >= 20 || $1 == 10) { return $gettok(ten twenty thirty forty fifty sixty seventy eighty ninety,$left($1,1),32) $digittoword($mid($1,2)) } elseif ($1 > 10) return $gettok(eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen,$mid($1,2),32) else return $digittoword($right($1,1)) } alias -l ThreeDigitsToWord { if ($1 == 0) return elseif ($1 >= 100) return $replace($gettok(one.hundred two.hundred three.hundred four.hundred five.hundred six.hundred seven.hundred eight.hundred nine.hundred,$left($1,1),32),$chr(46),$chr(32)) $twodigitstoword($mid($1,2)) else return $twodigitstoword($right($1,2)) } alias -l FourDigitsToWord { if ($1 == 0) return elseif ($1 >= 1000) return $gettok(one two three four five six seven eight nine,$left($1,1),32) $threedigitstoword($mid($1,2)) else return $threedigitstoword($right($1,3)) } alias -l FiveDigitsToWord { if ($1 == 0) return if ($1 >= 20000 || $1 == 10000) { return $gettok(ten twenty thirty forty fifty sixty seventy eighty ninety,$left($1,1),32) $fourdigitstoword($mid($1,2)) } elseif ($1 > 10000) return $gettok(eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen,$mid($1,2),32) else return $fourdigitstoword($right($1,4)) } alias -l SixDigitsToWord { if ($1 == 0) return elseif ($1 >= 100000) return $replace($gettok(one.hundred two.hundred three.hundred four.hundred five.hundred six.hundred seven.hundred eight.hundred nine.hundred,$left($1,1),32),$chr(46),$chr(32)) $fivedigitstoword($mid($1,2)) else return $fivedigitstoword($right($1,5)) } alias -l SevenDigitsToWord { if ($1 == 0) return elseif ($1 >= 1000000) return $gettok(one two three four five six seven eight nine,$left($1,1),32) $sixdigitstoword($mid($1,2)) else return $sixdigitstoword($right($1,6)) } alias -l EightDigitsToWord { if ($1 == 0) return if ($1 >= 20000000 || $1 == 10000000) { return $gettok(ten twenty thirty forty fifty sixty seventy eighty ninety,$left($1,1),32) $sevendigitstoword($mid($1,2)) } elseif ($1 > 10000000) return $gettok(eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen,$mid($1,2),32) else return $sevendigitstoword($right($1,7)) } alias -l NineDigitsToWord { if ($1 == 0) return elseif ($1 >= 100000000) return $gettok(one two three four five six seven eight nine,$left($1,1),32) $eightdigitstoword($mid($1,2)) else return $eightdigitstoword($right($1,8)) } alias -l NumberToWord.th { if ($1 == 0) return var %num $bytes($1,db) var %tok1 $gettok(%num,1,44) var %tok2 $gettok(%num,2,44) var %pad $right(000 $+ %tok2,3) if ($len($1) >= 4) return $sixdigitstoword(%tok1) thousand $sixdigitstoword(%pad) elseif ($len($1) < 4) return $threedigitstoword(%tok1) $threedigitstoword(%pad) } alias NumberToWord { :NumberToWord if ($1 <= 0) return zero if ($numtok($1,46) > 1) { tokenize 46 $1- | goto numbertoword } var %num $bytes($1,db) var %tok1 $gettok(%num,1,44) var %tok2 $remove($gettok(%num,2-3,44),$chr(44)) var %pad $right(000000 $+ %tok2,6) if ($len($1) >= 7) return $ninedigitstoword(%tok1) million $numbertoword.th(%pad) elseif ($len($1) >= 4) return $sixdigitstoword(%tok1) thousand $sixdigitstoword(%pad) elseif ($len($1) < 4) return $threedigitstoword(%tok1) }
_________________
|
|
|
|
 |
|
hixxy
|
Post subject: Re: $numbertoword Posted: Sun Aug 16, 2009 11:19 am |
|
| User |
 |
Joined: Tue Jan 15, 2008 11:31 am Posts: 133 Location: England
|
Here's one that pai made for a scripting challenge years ago: Code: alias ½ if ($1) return $3 $+ $gettok(OneTwoThreeFourFiveSixS7EightNineTenEl7TwelveThir+Four+Fif+Six+S7+Eigh+Nine+,$1,2) $2 alias numconv { var %o,%s,%i $remove($1,$chr(44)) if (!$regex(%i,/^(?=\S*\d)(\d{0,66}|0*)(\.\d*)?($| )/)) return $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 } return $iif(%o,$replace(%o,7,even,+t,t,lvet,nt,urt,rt,!,dec.,.,illion,+,teen),Zero) } Supports up to vigintillion and is considerably smaller 
|
|
|
|
 |
|
nayr
|
Post subject: Re: $numbertoword Posted: Mon Aug 17, 2009 11:17 pm |
|
 |
| User |
 |
Joined: Thu Jun 12, 2008 10:26 pm Posts: 450 Location: Someplace speshil
|
Cool script ^^ I shorted it cause i didnt want to type $numbertoword(blah) so I did $ntw($$1) 
_________________
|
|
|
|
 |
|
Imk0tter
|
Post subject: Re: $numbertoword Posted: Wed Aug 19, 2009 2:46 am |
|
| User |
 |
Joined: Thu Mar 08, 2007 4:45 am Posts: 225
|
Code: alias numbertoword { var %a -1,%z $1,%y 100 1000 1000000 1000000000 1000000000000 1000000000000000 1000000000000000000,%x hundred thousand million billion trillion quadrillion quintillion if (!%z) return $iif($2,$2,zero) if (%z < 1000) return $2 $(%z) while $calc(%z % $token(%y,%a,32)) == %z { dec %a } var %p $token(%y,%a,32) if ($len(%z) < 10) { var %k %z / %p,%k $int(%k) dec %z $calc(%p * %k) } else { var %n $v1 - 1,%n %n / 3,%n $int(%n) * 3,%k $left(%z,- $+ %n) dec %z %k $+ $str(0,%n) } scid 0 return $!numbertoword( %z , $2 $(%k) $token(%x,%a,32) ) } alias -l { var %a -1,%z $1,%x onetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteensixteenseventeeneighteennineteentwentytwenty onetwenty twotwenty threetwenty fourtwenty fivetwenty sixtwenty seventwenty eighttwenty ninethirtythirty onethirty twothirty threethirty fourthirty fivethirty sixthirty seventhirty eightthirty ninefourtyfourty onefourty twofourty threefourty fourfourty fivefourty sixfourty sevenfourty eightfourty ninefiftyfifty onefifty twofifty threefifty fourfifty fivefifty sixfifty sevenfifty eightfifty ninesixtysixty onesixty twosixty threesixty foursixty fivesixty sixsixty sevensixty eightsixty nineseventyseventy oneseventy twoseventy threeseventy fourseventy fiveseventy sixseventy sevenseventy eightseventy nineeightyeighty oneeighty twoeighty threeeighty foureighty fiveeighty sixeighty seveneighty eighteighty nineninetyninety oneninety twoninety threeninety fourninety fiveninety sixninety sevenninety eightninety nine if (%z < 100) return $token(%x,%z,2) return $token(%x,$int($calc(%z / 100)),2) hundred $iif($v1,$token(%x,$calc(%z % 100),2)) } Non-regex version, accurate up to "nine hundred ninety nine trillion nine hundred ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine"
_________________
|
|
|
|
 |
|
xmrfunny1x
|
Post subject: Re: $numbertoword Posted: Thu Aug 20, 2009 3:48 am |
|
| User |
 |
Joined: Sun Jul 27, 2008 7:26 pm Posts: 105 Location: New York
|
Talk about trolling a script. Way to totally give his script no credit guys, good job. Hey Stealth, since you use numbers less than 999,999,999 and mIRC's $calc can handle that without screwing it up, I would pass $1 through a $calc first and also strip all non-digits from $1, ie. var %c $calc($regsubex($1,/\D/g,)), to prevent things like this: Code: $numbertoword(00010) = ten thousand $numbertoword(000110) = one hundred ten thousand $numbertoword(230z) = two hundred thirty thousand
Other than that, I haven't come across any more roaches, I mean bugs!  I like this ^^
_________________ #xmrfunny1x
|
|
|
|
 |
|
Page 1 of 1
|
[ 5 posts ] |
|
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|
|
|