Convert 5 digit integers to pure text: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(SF: fourty -> forty.)
m (Updated author and download links, and changed format of some pages.)
Line 263: Line 263:
-Stu
-Stu


Page author: Afrow UK
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 12:36, 23 April 2005

Description

This is a rather useless script, which I made because I was bored :p It converts a number (5 digits max) to pure text.

Usage

Push 96345
Call ConvertInt2Str
Pop $R0

$R0 will now be: "ninety-six thousand, three hundred, and forty-five"

The Function

Function ConvertInt2Str
  Exch $0 ; input string
  Push $1
  Push $2
  Push $3
  Push $4
  Push $5
  Push $6
  StrLen $1 $0
  StrCmp $1 6 error
  StrCpy $3 ""
  StrCpy $2 ""
  StrCpy $4 $0
  StrCmp $1 3 0 +2
   StrCpy $4 $0 1 -1
  StrCmp $1 4 0 +2
   StrCpy $4 $0 1 -1
  StrCmp $1 5 0 +2
   StrCpy $4 $0 1 -1
  StrCmp $0 0 0 +2
   StrCpy $3 zero
  StrCmp $4 1 0 +2
   StrCpy $3 one
  StrCmp $4 2 0 +2
   StrCpy $3 two
  StrCmp $4 3 0 +2
   StrCpy $3 three
  StrCmp $4 4 0 +2
   StrCpy $3 four
  StrCmp $4 5 0 +2
   StrCpy $3 five
  StrCmp $4 6 0 +2
   StrCpy $3 six
  StrCmp $4 7 0 +2
   StrCpy $3 seven
  StrCmp $4 8 0 +2
   StrCpy $3 eight
  StrCmp $4 9 0 +2
   StrCpy $3 nine
  StrCmp $0 1 done
  StrCmp $4 10 0 +2
   StrCpy $3 ten
  StrCmp $4 11 0 +2
   StrCmp $1 2 0 back1
   StrCpy $4 $0 2 -1
   StrCpy $3 eleven
  StrCmp $4 12 0 +2
   StrCpy $3 twelve
  StrCmp $4 13 0 +2
   StrCpy $3 thirteen
  StrCmp $4 14 0 +2
   StrCpy $3 fourteen
  StrCmp $4 15 0 +2
   StrCpy $3 fifteen
  StrCmp $4 16 0 +2
   StrCpy $3 sixteen
  StrCmp $4 17 0 +2
   StrCpy $3 seventeen
  StrCmp $4 18 0 +2
   StrCpy $3 eighteen
  StrCmp $4 19 0 +2
   StrCpy $3 nineteen
  StrCpy $1 $0 1 -2
  StrCmp $1 2 0 +4
   StrCpy $3 twenty
   StrCpy $4 $0 1 -1
   Goto getend1
  StrCmp $1 3 0 +4
   StrCpy $3 thirty
   StrCpy $4 $0 1 -1
   Goto getend1
  StrCmp $1 4 0 +4
   StrCpy $3 forty
   StrCpy $4 $0 1 -1
   Goto getend1
  StrCmp $1 5 0 +4
   StrCpy $3 fifty
   StrCpy $4 $0 1 -1
   Goto getend1
  StrCmp $1 6 0 +4
   StrCpy $3 sixty
   StrCpy $4 $0 1 -1
   Goto getend1
  StrCmp $1 7 0 +4
   StrCpy $3 seventy
   StrCpy $4 $0 1 -1
   Goto getend1
  StrCmp $1 8 0 +4
   StrCpy $3 eighty
   StrCpy $4 $0 1 -2
   Goto getend1
  StrCmp $1 9 0 +4
   StrCpy $3 ninety
   StrCpy $4 $0 1 -1
   Goto getend1
back1:
  StrLen $1 $0
  StrCmp $1 1 done
  StrCmp $1 2 done
  StrCpy $4 $0 1 -3
  Goto gethundred1
back2:
  StrCmp $1 3 done
  StrCpy $4 $0 1 -4
  Goto getthousand1
error:
MessageBox MB_OK "Error: integer is too long (too many digits!) \
$\nYou must use an integer less than 6 digits long."
StrCpy $0 error
Goto done
getthousand1:
  StrCpy $4 $0 2 -5
  StrCmp $4 10 0 +2
   StrCpy $5 "ten thousand, "
  StrCmp $4 11 0 +2
   StrCpy $5 "eleven thousand, "
  StrCmp $4 12 0 +2
   StrCpy $5 "twelve thousand, "
  StrCmp $4 13 0 +2
   StrCpy $5 "thirteen thousand, "
  StrCmp $4 14 0 +2
   StrCpy $5 "fourteen thousand, "
  StrCmp $4 15 0 +2
   StrCpy $5 "fifteen thousand, "
  StrCmp $4 16 0 +2
   StrCpy $5 "sixteen thousand, "
  StrCmp $4 17 0 +2
   StrCpy $5 "seventeen thousand, "
  StrCmp $4 18 0 +2
   StrCpy $5 "eighteen thousand, "
  StrCmp $4 19 0 +2
   StrCpy $5 "nineteen thousand, "
  StrCpy $2 $4 1 -2
  StrCmp $2 2 0 +4
   StrCpy $1 "twenty"
   StrCpy $6 " thousand, "
   Goto getthousand3
  StrCmp $2 3 0 +4
   StrCpy $1 "thirty"
   StrCpy $6 " thousand, "
   Goto getthousand3
  StrCmp $2 4 0 +4
   StrCpy $1 "forty"
   StrCpy $6 " thousand, "
   Goto getthousand3
  StrCmp $2 5 0 +4
   StrCpy $1 "fifty"
   StrCpy $6 " thousand, "
   Goto getthousand3
  StrCmp $2 6 0 +4
   StrCpy $1 "sixty"
   StrCpy $6 " thousand, "
   Goto getthousand3
  StrCmp $2 7 0 +4
   StrCpy $1 "seventy"
   StrCpy $6 " thousand, "
   Goto getthousand3
  StrCmp $2 8 0 +4
   StrCpy $1 "eighty"
   StrCpy $6 " thousand, "
   Goto getthousand3
  StrCmp $2 9 0 +4
   StrCpy $1 "ninety"
   StrCpy $6 " thousand, "
getthousand3:
  StrCpy $2 $4 1 -1
  StrCmp $2 0 0 +2
   StrCpy $5 ""
  StrCmp $2 1 0 +2
   StrCpy $5 -one
  StrCmp $2 2 0 +2
   StrCpy $5 -two
  StrCmp $2 3 0 +2
   StrCpy $5 -three
  StrCmp $2 4 0 +2
   StrCpy $5 -four
  StrCmp $2 5 0 +2
   StrCpy $5 -five
  StrCmp $2 6 0 +2
   StrCpy $5 -six
  StrCmp $2 7 0 +2
   StrCpy $5 -seven
  StrCmp $2 8 0 +2
   StrCpy $5 -eight
  StrCmp $2 9 0 +2
   StrCpy $5 -nine
  StrCpy $3 "$1$5$6$3"
  Goto done
gethundred1:
  StrCmp $4 0 0 +2
   StrCpy $5 ""
  StrCmp $4 1 0 +2
   StrCpy $5 "one hundred, and "
  StrCmp $4 2 0 +2
   StrCpy $5 "two hundred, and "
  StrCmp $4 3 0 +2
   StrCpy $5 "three hundred, and "
  StrCmp $4 4 0 +2
   StrCpy $5 "four hundred, and "
  StrCmp $4 5 0 +2
   StrCpy $5 "five hundred, and "
  StrCmp $4 6 0 +2
   StrCpy $5 "six hundred, and "
  StrCmp $4 7 0 +2
   StrCpy $5 "seven hundred, and "
  StrCmp $4 8 0 +2
   StrCpy $5 "eight hundred, and "
  StrCmp $4 9 0 +2
   StrCpy $5 "nine hundred, and "
  StrCpy $3 "$5$3"
  Goto back2
getend1:
  StrCmp $4 0 0 +2
   StrCpy $5 ""
  StrCmp $4 1 0 +2
   StrCpy $5 one
  StrCmp $4 2 0 +2
   StrCpy $5 two
  StrCmp $4 3 0 +2
   StrCpy $5 three
  StrCmp $4 4 0 +2
   StrCpy $5 four
  StrCmp $4 5 0 +2
   StrCpy $5 five
  StrCmp $4 6 0 +2
   StrCpy $5 six
  StrCmp $4 7 0 +2
   StrCpy $5 seven
  StrCmp $4 8 0 +2
   StrCpy $5 eight
  StrCmp $4 9 0 +2
   StrCpy $5 nine
  StrCpy $3 "$3-$5"
  StrCpy $5 $3 1 -1
   StrCmp $5 - 0 +2
   StrCpy $3 $3 -1
  Goto back1
done:
  StrCpy $0 $3
  Pop $1
  Pop $2
  Pop $3
  Pop $4
  Pop $5
  Pop $6
  Exch $0 ; output string
FunctionEnd

Written by Afrow UK on 2nd May 2003 -Stu

Page author: Afrow UK