Solved

Retaining floating point values in Sybase

Posted on 2012-03-27
4
864 Views
Last Modified: 2012-06-27
Hi Experts...
I have a calculation to be done in a query as shown below:
 ((28154/3745181) * 100) whose resultant vaalue is .751739 which i want it as 0.75
But when i try to do in a query i get 0 as shown below.

select  ((28154/3745181) * 100) --Returns 0 as the result.
How can i get the desired 0.75 as the resultant.
Please help...
0
Comment
Question by:gaugeta
4 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
0
 

Author Comment

by:gaugeta
Comment Utility
@DaveBaldwin:Thanks for the reply.
I still get 0.00 as the result.
Please help...
0
 
LVL 14

Assisted Solution

by:Jan_Franek
Jan_Franek earned 250 total points
Comment Utility
Sybase automaticaly converts result to the same datatype as the parameters. So 28154/3745181 will result in 0 (result truncated).

So you need to convert one of parameters to float or other similar type:

select convert(float,28154)/3745181 will give you 0.0075173936853786235

Then you can use round function to get desired result:

select round(  ((convert(float,28154)/3745181) * 100) , 2 )
0
 
LVL 13

Accepted Solution

by:
alpmoon earned 250 total points
Comment Utility
What are the actual datatypes? You can get the actual value by just adding '.0' without conversion if you are using constants:

select round( ( (28154/3745181.0) * 100) , 2 )
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now