• Status: Solved
• Priority: Medium
• Security: Public
• Views: 279

# Convert INT to DECIMAL with 1 digit Precision

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
sath350163
2 Solutions

Commented:
SELECT Cast ( ( (CAST(636 AS DECIMAL(18,2))/80)/3 ) as DECIMAL(18,1))
0

freelancerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.