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

x
Solved

# SQL round decimal

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

LVL 4

Expert Comment

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

LVL 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
0

LVL 4

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.
0

LVL 1

Author Comment

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

## Featured Post

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.
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…
###### Suggested Courses
Course of the Month6 days, 14 hours left to enroll