Solved

Convert INT to DECIMAL with 1 digit Precision

Posted on 2014-03-11
2
243 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
ID: 39919951
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
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

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

810 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