Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL round decimal

Posted on 2010-08-25
4
Medium Priority
?
1,372 Views
Last Modified: 2012-05-10
In a large select stmt, on of the columns I am reading from contains a number (double). This column may contain a whole number, or may contain a decimal. Sometimes the decimal is very long.

I am looking to round the decimial to 4, but only when required. If the number is whole or less than 4 decimals I prefer it stay that way.

How would I do this?
I am quering against a DB2 database
0
Comment
Question by:JDCam
  • 3
4 Comments
 
LVL 4

Expert Comment

by:GO-87
ID: 33522953
Would this work?
SELECT ROUND (MyNumber,  4)
0
 
LVL 4

Accepted Solution

by:
GO-87 earned 2000 total points
ID: 33522981
Oh I see what you're asking. Does this work?
SELECT (ROUND(MyNumber*10000),0)/10000
0
 
LVL 4

Expert Comment

by:GO-87
ID: 33523036
Note: TRUNC will truncate decimal places (i.e. lose digits),
whereas ROUND will round down or up to the nearest value, to the specified number of decimal places.
0
 
LVL 1

Author Comment

by:JDCam
ID: 33523048
I think so.... good thinking, very logical.
I will test some more but looks to give the right output.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

916 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