January 14, 2005 at 4:36 pm
I have two integers that I need a percentage number from such as
50/5000 = 5.00%
I Know I ought to Cast out the datatype of the percentage etc... I do not remember what the formatting was... and didn't see it in my former posts many thanks for your help...
-- Francisco
January 14, 2005 at 6:38 pm
First point is that the result of your example equates to 1%, not 5%
Secondly, there is no explicit 'percentage' datatype. Not that it matters, as
select 50 / cast(5000 as float)
returns 0.01 and
select 100 * 50 / cast(5000 as float)
returns 1.0.
Regards
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
January 16, 2005 at 12:27 am
awesome, thanks for the answer...
I found out I can also use a + .00 so my select would include
(Field1 + .00) / (Field2 +.00) and that also helped to give the desired value add a * 100 and convert to decimal 2,2 with the appended '%' and it all looks good to mgmt
your help is much appreciated
-- Francisco
January 16, 2005 at 2:01 pm
You may experience some "wierd" answers when using FLOAT because it does it's math in a binary rather than decimal fashion.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 16, 2005 at 5:25 pm
Thanks Jeff - do you have any examples of this?
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply