Solved

SQL round decimal

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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