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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
whereas ROUND will round down or up to the nearest value, to the specified number of decimal places.
ASKER
I think so.... good thinking, very logical.
I will test some more but looks to give the right output.
I will test some more but looks to give the right output.
SELECT ROUND (MyNumber, 4)