Solved

Retaining floating point values in Sybase

Posted on 2012-03-27
4
870 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 83

Expert Comment

by:Dave Baldwin
ID: 37770480
0
 

Author Comment

by:gaugeta
ID: 37770488
@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
ID: 37771725
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
ID: 37773679
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 74
Save conflict messages on existing documents 15 74
How to SQL Trace a SPECIFIC query 24 84
AWS RDS Backups? 3 52
I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

821 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