Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Rounding numbers in ASP

Posted on 2004-10-31
9
Medium Priority
?
273 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:kerrj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 12457236
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
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12457237
oops. <%=formatnumber(ccur(".075")*100,2)%> also works for me, returned 7.50% as expected
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12457333
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Expert Comment

by:Garve
ID: 12457596
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12457763
I am not sure how the datatype could be integer if it is storing a value of .075

FtB
0
 

Author Comment

by:kerrj
ID: 12457817
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
 

Author Comment

by:kerrj
ID: 12457828
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12458094
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
 

Author Comment

by:kerrj
ID: 12458151
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question