Convert INT to DECIMAL with 1 digit Precision

Posted on 2014-03-11
Last Modified: 2014-03-22
I'm trying to get a value with 1 digit precision when I do the below calculation:

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?

Question by:sath350163
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
LVL 39

Accepted Solution

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

Assisted Solution

PortletPaul earned 250 total points
ID: 39920170
try this perhaps?
, (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:

|     2.65 |     2.65 |     2.65 |      2.7 |      2.7 |      2.7 |


Open in new window


Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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