Solved

SQL round decimal

Posted on 2010-08-25
4
1,347 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 500 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
 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now