Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a float to display as a Percentage in Query

Status
Not open for further replies.

AccessUser22

Technical User
Jan 23, 2003
168
0
0
US
Is there a way to format a floating integer to display as a percentage inside of a query?

I have the number stored in the table as 0.75. However, I would like to display it inside the query as 75.00%.

Is there any way to do this besides converting to decimal(18,2) and multiplying by 100?

 
Why do you need to convert anything?

Code:
select cast(.75 * 100 as varchar) + '%'

That being said, formatting should probably be reserved for your presentation layer, as in most cases it will accomplish the task more efficiently.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
I realize that now, Thanks.

Can't format it on the presentation layer since depending on other data - This percentage appears as part of a text string. We handle most of our complex formatting on the db side since if a change needs to be made, it's quicker for me to just go into the view and alter it there. Plus, I am the one who logics out most of the reasoning and I don't have easy access to go into the web pages to do this. So I handle a lot of the complex formatting in the db side. Then it automatically shows up on the web if I need to change it.

Things like shading cells and formatting a number as money, etc gets passed on the web group, agreed.
 
Numbers should never be stored as float -this is not an exact numeric type and if you are doing any cacluations on them, you need to change the data type permanently or you will evntually get rounding errors that add up to big problems.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top