Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Convert INT to DECIMAL with 1 digit Precision

Posted on 2014-03-11
2
Medium Priority
?
268 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
[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
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
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

by:PortletPaul
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

Open in new window

0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

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.

648 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