Solved

Convert INT to DECIMAL with 1 digit Precision

Posted on 2014-03-11
2
232 Views
Last Modified: 2014-03-22
Hello,
   
I'm trying to get a value with 1 digit precision when I do the below calculation:
((636/80)/3)


I tried casting the numerator as DECIMAL, but I get a final result with 8 decimal places as shown below.

SELECT (CAST(636 AS DECIMAL(18,2))/80)/3
Result: 2.65000000

Open in new window


But I want only 1 decimal place in the result as 2.7

How do I achieve this?

Thanks!
0
Comment
Question by:sath350163
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
Comment Utility
SELECT Cast ( ( (CAST(636 AS DECIMAL(18,2))/80)/3 ) as DECIMAL(18,1))
0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
Comment Utility
try this perhaps?
SELECT
  (636.0/80)/3
, (636/80.0)/3
, (636/80.0)/3.0
, ROUND( (636.0/80)/3 , 1) -- shows as 2.7
, ROUND( (636/80.0)/3 , 1) -- shows as 2.7
, ROUND( (636/80.0)/3.0 , 1) -- shows as 2.7
	
results of this:

| COLUMN_0 | COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 |
|----------|----------|----------|----------|----------|----------|
|     2.65 |     2.65 |     2.65 |      2.7 |      2.7 |      2.7 |

see: http://sqlfiddle.com/#!6/d41d8/15736

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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

7 Experts available now in Live!

Get 1:1 Help Now