x
Solved

# Convert INT to DECIMAL with 1 digit Precision

Posted on 2014-03-11
Medium Priority
268 Views
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
``````

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

How do I achieve this?

Thanks!
0
Question by:sath350163
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 39

Accepted Solution

Pratima Pharande earned 1000 total points
ID: 39919951
SELECT Cast ( ( (CAST(636 AS DECIMAL(18,2))/80)/3 ) as DECIMAL(18,1))
0

LVL 49

Assisted Solution

PortletPaul earned 1000 total points
ID: 39920170
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
``````
0

## Featured Post

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.
###### Suggested Courses
Course of the Month15 days, 8 hours left to enroll