Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: number string text
This code can convert valid number with or without decimals. ; NOTE: that number cannot exceed 999 million
For Example: the number 69481 would be returned as 'Sixty Nine Thousand Four Hundred Eighty One'.
#DefineFunction initnum() aR = ArrDimension(100) aR[0] = "Zero" aR[1] = "One" aR[2] = "Two" aR[3] = "Three" aR[4] = "Four" aR[5] = "Five" aR[6] = "Six" aR[7] = "Seven" aR[8] = "Eight" aR[9] = "Nine" aR[10] = "Ten" aR[11] = "Eleven" aR[12] = "Twelve" aR[13] = "Thirteen" aR[14] = "Fourteen" aR[15] = "Fifteen" aR[16] = "Sixteen" aR[17] = "Seventeen" aR[18] = "Eighteen" aR[19] = "Nineteen" aR[20] = "Twenty" aR[21] = "Twenty One" aR[22] = "Twenty Two" aR[23] = "Twenty Three" aR[24] = "Twenty Four" aR[25] = "Twenty Five" aR[26] = "Twenty Six" aR[27] = "Twenty Seven" aR[28] = "Twenty Eight" aR[29] = "Twenty Nine" aR[30] = "Thirty" aR[31] = "Thirty One" aR[32] = "Thirty Two" aR[33] = "Thirty Three" aR[34] = "Thirty Four" aR[35] = "Thirty Five" aR[36] = "Thirty Six" aR[37] = "Thirty Seven" aR[38] = "Thirty Eight" aR[39] = "Thirty Nine" aR[40] = "Forty" aR[41] = "Forty One" aR[42] = "Forty Two" aR[43] = "Forty Three" aR[44] = "Forty Four" aR[45] = "Forty Five" aR[46] = "Forty Six" aR[47] = "Forty Seven" aR[48] = "Forty Eight" aR[49] = "Forty Nine" aR[50] = "Fifty" aR[51] = "Fifty One" aR[52] = "Fifty Two" aR[53] = "Fifty Three" aR[54] = "Fifty Four" aR[55] = "Fifty Five" aR[56] = "Fifty Six" aR[57] = "Fifty Seven" aR[58] = "Fifty Eight" aR[59] = "Fifty Nine" aR[60] = "Sixty" aR[61] = "Sixty One" aR[62] = "Sixty Two" aR[63] = "Sixty Three" aR[64] = "Sixty Four" aR[65] = "Sixty Five" aR[66] = "Sixty Six" aR[67] = "Sixty Seven" aR[68] = "Sixty Eight" aR[69] = "Sixty Nine" aR[70] = "Seventy" aR[71] = "Seventy One" aR[72] = "Seventy Two" aR[73] = "Seventy Three" aR[74] = "Seventy Four" aR[75] = "Seventy Five" aR[76] = "Seventy Six" aR[77] = "Seventy Seven" aR[78] = "Seventy Eight" aR[79] = "Seventy Nine" aR[80] = "Eighty" aR[81] = "Eighty One" aR[82] = "Eighty Two" aR[83] = "Eighty Three" aR[84] = "Eighty Four" aR[85] = "Eighty Five" aR[86] = "Eighty Six" aR[87] = "Eighty Seven" aR[88] = "Eighty Eight" aR[89] = "Eighty Nine" aR[90] = "Ninety" aR[91] = "Ninety One" aR[92] = "Ninety Two" aR[93] = "Ninety Three" aR[94] = "Ninety Four" aR[95] = "Ninety Five" aR[96] = "Ninety Six" aR[97] = "Ninety Seven" aR[98] = "Ninety Eight" aR[99] = "Ninety Nine" Return(aR) #EndFunction #DefineFunction num2txt(n,flag) ; n is assumed to be a Valid Number with or without decimals ; right now n cannot exceed 999 million ; flag is either 0 or 1, if 1 return results as currency c = Strcat(n,"") d = "" aR = initnum() x = StrIndex(c, ".",1,@FWDSCAN) If x>0 d = StrSub(c,x+1,-1) If StrSub(c,1,1) == "." c="0" Else c = StrSub(c,1,x-1) Endif Endif If d<>"" If flag==1 If StrLen(d) == 1 d = Strcat(d,"0") Endif d= aR[ Int( StrSub(d,1,2) ) ] d= StrReplace(d," ","-") d= StrCat( " and ",d," Cents") Else x= "" For i= 1 To StrLen(d) x = StrCat( x, aR[ Int( StrSub(d,i,1) ) ]," ") Next d = StrCat(" [point] ",x) Endif Endif x="" If c== "0" If Flag == 0 x = aR[0] Else x = "No " Endif Else If StrLen(c) == 9 x = StrCat( x, aR[ Int( StrSub(c,1,1) ) ]," Hundred ") x = StrCat( x, aR[ Int( StrSub(c,2,2) ) ]," Million ") c = StrSub(c,4,-1) Endif If StrLen(c) == 8 x = StrCat( x, aR[ Int( StrSub(c,1,2) ) ]," Million ") c = StrSub(c,3,-1) Endif If StrLen(c) == 7 x = StrCat( x, aR[ Int( StrSub(c,1,1) ) ]," Million ") c = StrSub(c,2,-1) Endif If StrLen(c) == 6 x = StrCat( x, aR[ Int( StrSub(c,1,1) ) ]," Hundred ") x = StrCat( x, aR[ Int( StrSub(c,2,2) ) ]," Thousand ") c = StrSub(c,4,-1) Endif If StrLen(c) == 5 x = StrCat( x, aR[ Int( StrSub(c,1,2) ) ]," Thousand ") c = StrSub(c,3,-1) Endif If StrLen(c) == 4 x = StrCat( x, aR[ Int( StrSub(c,1,1) ) ]," Thousand ") c = StrSub(c,2,-1) Endif If StrLen(c) == 3 x = StrCat( x, aR[ Int( StrSub(c,1,1) ) ]," Hundred ") x = StrCat( x, aR[ Int( StrSub(c,2,2) ) ]," ") c = "" Endif If StrLen(c) == 2 x = StrCat( x, aR[ Int( StrSub(c,1,2) ) ]," ") c = "" Endif If StrLen(c) == 1 x = StrCat( x, aR[ Int( StrSub(c,1,1) ) ]," ") c = "" Endif Endif If flag == 1 x= Strcat(x," Dollars ") Endif x= StrCat(x,d) x= StrReplace(x," "," ") Return(x) #EndFunction ;test number formatting z = 9999481 y = num2txt(z,0) message(z,y) z = 69481 y = num2txt(z,0) message(z,y) z = 641.25 y = num2txt(z,1) message(z,y) z = 641.25 y = num2txt(z,0) message(z,y) z = .75 y = num2txt(z,1) message(z,y) z = .92 y = num2txt(z,0) message(z,y) z = .7 y = num2txt(z,1) message(z,y) z = .7 y = num2txt(z,0) message(z,y) exit
Article ID: W15004
File Created: 2001:11:08:12:41:20
Last Updated: 2001:11:08:12:41:20