NumberToString Function:
Convert any number to a string
Description:
NumberToString Function converts any number to a string
Syntax:
string = NumberToString(Number, Type)
Details:
Type: none, number, letter, euro, dollar
Example:
<%
Dim n n = 12345.67 response.write NumberToString(n, "number") '--- returns: twelve thousand three hundred fourty-five/67 response.write NumberToString(n, "letter") '--- returns: twelve thousand three hundred fourty-five and sixty-seven response.write NumberToString(n, "euro") '--- returns: twelve thousand three hundred fourty-five euros and sixty-seven cents response.write NumberToString(n, "dollar") '--- returns: twelve thousand three hundred fourty-five dollars and sixty-seven cents
%>
ASP Source Code:
<%
Function NumberToString(ByVal number, ByVal numType) '--- numType : none, number, letter, euro, dollar Dim i, dec, lun, lett, num, str, tmp, plu Dim tri(5) number = cdbl(number) dec = Right(formatnumber(number, 2), 2) num = cstr(fix(number)) numType = LCase(numType) Str = cstr("000000000000000000000" & num) lun = len(Str) for i = 1 to 5 tri(i) = mid(Str, lun - (i * 3) + 1, 3) if tri(i) > 0 then lett = Transform3(tri(i), i) & lett next If lett = "" then lett = "zero" If numType = "letter" Then tmp = lett & " and "& Transform3("0"&dec, 0) ElseIf numType = "euro" Or numType = "dollar" Then If num = 0 Or num = 1 Then plu = "" Else plu = "s" If dec = 0 then tmp = lett & " " & numType & plu '& " and zero cent" ElseIf dec = 1 then tmp = lett & " " & numType & plu & " and one cent" ElseIf dec > 1 then tmp = lett & " " & numType & plu & " and " & Transform3("0"&dec, 0) & " cents" End if Else '--- none, number tmp = lett & "/"&dec End if NumberToString = tmp End Function '-------------------------------------------- Function Transform3(ByVal tri, ByVal ordinal) dim ltwo, ris, dec, uni dim n(30) n(0) = "" n(1) = "one":n(2) = "two":n(3) = "three":n(4) = "four":n(5) = "five" n(6) = "six":n(7) = "seven":n(8) = "eight":n(9) = "nine":n(10) = " ten" n(11) = " eleven":n(12) = " twelve":n(13) = "thirteen":n(14) = "fourteen":n(15) = "fifteen" n(16) = " sixteen":n(17) = " seventeen":n(18) = " eighteen":n(19) = " nineteen" n(22) = " twenty":n(23) = " thirty":n(24) = " fourty":n(25) = " fifty" n(26) = " sixty":n(27) = " seventy":n(28) = " eighty":n(29) = " ninety" If left(tri, 1) = 1 then ris = " one hundred" if left(tri, 1) > 1 then ris = n(cint(left(tri, 1))) & " hundred" ltwo = cint(right(tri, 2)) if ltwo < 20 then ris = ris & n(ltwo) else dec = mid(tri, 2, 1) uni = right(tri, 1) ris = ris & n(20 + dec) Ris = ris & "-" & n(uni) end if if ordinal = 2 then ris = ris & " thousand " if tri = 1 then ris = " one thousand " end if if ordinal = 3 then ris = ris & " million " if tri = 1 then ris = " one million " end if if ordinal = 4 then ris = ris & " billion " if tri = 1 then ris = " one billion " end if if ordinal = 5 then ris = ris & " trillion " if tri = 1 then ris = " one trillion " end if Transform3 = Ris End Function
%>
|