Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


SQL round decimal

Posted on 2010-08-25
Medium Priority
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
Question by:JDCam
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
  • 3

Expert Comment

ID: 33522953
Would this work?
SELECT ROUND (MyNumber,  4)

Accepted Solution

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

Expert Comment

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.

Author Comment

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 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