ASP solution to format number as percentage?

Using vbscript, is the FormatPecent function available? When I tried to format a rst field I received an error.

I return a rst field from SQL that is already multiplied by 100 in the back end, so without applying any client side formatting, the numbers display like this:
8.36
4.7
4.26

I want to display:
8.36%
4.70%
4.26%

What is the most efficient way to accomplish this using vbscript ASP?

Thanks!
LVL 1
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
<%
x = 8.55555
y = Round(x,2)
response.write y & "%"
%>
Commented:
You can use formatpercent(), but remember that doing so will multiply your number by 100.

So FormatPercent(8.36) will give you 836%

So do it this way:

response.write(FormatPercent(objRS("YourField")*100))

FtB
Commented:
a better one would be

<%
x = 8.555
if Len(x) < 4 then
x = x&"0"
response.write x
else
y = Round(x,2)
response.write y & "%"
end if
%>
Commented:
my original post didnt take into account those numbers that didnt have at least 2 decimal places
Author Commented:
fritz the blank,
my complete line of code is
Response.Write("<td><font face='Arial' size='2'>" & rst("percent_sent") &"</font></td>")

If I try to use
Response.Write("<td><font face='Arial' size='2'>" & FormatPercent( rst("percent_sent"))&"</font></td>")

I receive a type mismatch.

As far as the result, I guess I could either divide it by 100 as you suggest (you say multiply but I'm pretty sure you meant divide..)
or I can change my back end process so I don't multiply there.
Commented:
Please give this a shot:

Response.Write("<td><font face='Arial' size='2'>" & FormatPercent(rst("percent_sent")*.01) &"</font></td>")
Commented:
You are right, I did mean divide, but *.01 should do it.

FtB
Author Commented:
fritz_the_blank,

Still receive the type mismatch error, but I believe it has something to do with the underlying rst field rather than being a problem with the FormatPercent function,
because I get a type mismatch if I do ANY kind of mathmatical operation, for example
dim myVal
myVal = rst("percent_sent")
myVal = myVal/100---------------------------------------->I get a type mismatch here also

Here's the SQL for the field, if that helps....
CAST(CAST(call_ct AS decimal)
/ CAST(pnrcount  AS decimal) * 100 AS decimal(9, 2))

Commented:
Do you get an error if you do this?

Response.write(CDbl(rst("percent_sent")))

FtB
Author Commented:
no error,it works ok
Commented:
Okay, then what if you do this then?

Response.write(FormatPercent(CDbl(rst("percent_sent"))))

FtB

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thanks ftb, that works!
Vince
Commented:
Glad to have helped,

FtB
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.