Manny
Manny

Reputation: 103

How to Round Decimal Result of a Calculated Column in Oracle SQL

I have a calculated column in Oracle that returns a number that is very long because of decimals (ex: 200000.0044068030021345452041589203332645).

Is there a way to convert this to say 200000.00? I tried Round, TO_DECIMAL, CAST. But nothing seems to work.

SELECT
CASE
     WHEN TRD = 'FUT'
     THEN
         CASE
             WHEN BUY_SELL = 'BUY' 
             THEN CUR / PRC 
             ELSE -CUR / PRC
         END
     ELSE NULL
END AS UNITS
FROM LAN.Details

Upvotes: 1

Views: 999

Answers (1)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31991

use round

  select round(200000.0044068030021345452041589203332645,2) from dual

so in your query

SELECT
CASE
     WHEN TRD = 'FUT'
     THEN
         CASE
             WHEN BUY_SELL = 'BUY' 
             THEN round( CUR / PRC ,2)
             ELSE round(-CUR / PRC,2)
         END
     ELSE NULL
END AS UNITS
FROM LAN.Details

Upvotes: 3

Related Questions