Link to home
Start Free TrialLog in
Avatar of JDCam
JDCam

asked on

SQL round decimal

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
Avatar of GO-87
GO-87

Would this work?
SELECT ROUND (MyNumber,  4)
ASKER CERTIFIED SOLUTION
Avatar of GO-87
GO-87

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of JDCam

ASKER

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