Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How do you generally handle percentages?

Author  Topic 

gnobber
Starting Member

11 Posts

Posted - 2009-09-21 : 02:58:10
Im having quite a problem in my application. I have an amount that is divided into 3. The amount is 9000. I need to store the percentage in SQL Server and not the exact amount when divided into 3. Of course 9000 would yield (when divided into 3) 3000 but in terms of percentage, it would be three .3333333 something. If I need to retrieve the value, .3333333 x 9000 would of course not be exactly 3000 but 2999.9997. But in my application, I cannot use rounding since I cannot be sure if the value needs to be rounded or that is really the value exactly needed. Does anybody have any idea on what I might try to change or do to so I can retrieve the correct value?

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-09-21 : 03:21:31
Well...if you *have* to store the percentage then it'll be inaccurate no matter what you do because of the issue you just mentioned. I did have this same problem once and I tries saving the percentage with 8 decimals or something and the amounts with 4 and that sort of worked if I recall correctly but it was definitely a hack. How about saving the factor you are dividing by instead...? Then whenever you need to display the percentage for some reason you just display "100/factor"...?

- Lumbago
Go to Top of Page

gnobber
Starting Member

11 Posts

Posted - 2009-09-21 : 03:45:36
Hi Lumbago,

Well, I guess you're right. I will never get the exact value if I used the method that I've just written. It's not actually the percentage that I need to display. I need to be able to display the value of 3000 with what's available to me: the 9000 and the percentage (33%). But maybe Im approaching it wrong. Anyway, thanks for the suggestion. I really want to post the exact situation so I can get some help but it's pretty long and needs lot of explanation. I'll try to write it up first then i'll post it. Thanks again!
Go to Top of Page
   

- Advertisement -