Rounding numbers in ASP

I have a number .075 which is being pulled from a sql server database.  I want to mulitply the number by 100 and display it as a percentage.  My code below always rounds the value up to 8.00% where as I would rather it say 7.50%.  How can I fix this.

formatnumber(ccur(rsRec("discount"))*100,2)%>%

Thanks,
Jon
kerrjAsked:
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.

Ryan ChongCommented:
This works fine for me:

<%=formatnumber(cdbl(".075")*100,2)%>

then problem may be is on the value of rsRec("discount")

try check it and make sure its value is .075 ?
0

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.

Start your 7-day free trial
Ryan ChongCommented:
oops. <%=formatnumber(ccur(".075")*100,2)%> also works for me, returned 7.50% as expected
0
fritz_the_blankCommented:
I don't see why you even need the CCur() method here. Why not just:

formatnumber(rsRec("discount")*100,2)%>%

or

round(rsRec("discount")*100,2)%>%

FtB
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

GarveCommented:
Is the field in the database and integer field (long or short)? If so the number will be being rounded up when entered into the db. Try setting the number type as 'double'.
0
fritz_the_blankCommented:
I am not sure how the datatype could be integer if it is storing a value of .075

FtB
0
kerrjAuthor Commented:
The reason why I have to do a conversion on the data is because it is a numeric data type in SQL Server.  I get a Type mismatch if you do not do a conversion.  The option of coverting to Cdbl rounds to 8.00 as well.  There must be a way to do this other than changing the data type?

Thanks,
Jon
0
kerrjAuthor Commented:
Yes the conversion will work if you hard code the numbers in, it will not work if you pull the data from SQL Server database.
0
fritz_the_blankCommented:
If it is numeric, then you should be able to use the round function. I think that there is something that I am missing here.

FtB
0
kerrjAuthor Commented:
round(rsRec("discount")*100,2)  'returns a type mismatch error
round(rsRec("discount"),2)*100  'returns the value as 8% when it should be 7.5% (the DB value is .075)

 ryancys was correct originally.  During the time I was testing this someone actually changed the value to .08 so I changed it back to .075 again to test and it does work with Cdbl() as mentioned above or as follows...

Cdbl(rsRec("discount"))*100

Thanks,
Jon
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.