Home > database >  Limiting floats to two decimal points in oracle sql
Limiting floats to two decimal points in oracle sql

Time:06-30

I have values structured like this:

14.996
2248.43
-2334.06
12.2333334455 
74.38133333333328

And I want it to become this:

15.00
2248.43
-2334.06
12.24
74.40 

Using an sql query in oracle db? maintaining only 3 decimal points. Tried CAST and TO_NUMBER with formatting but it didn't work.

CodePudding user response:

Well CAST can certainly be made to work here, e.g.

SELECT CAST(74.38133333333328 AS NUMERIC(10,3)) AS output
FROM dual;

-- 74.381

For notes, NUMERIC(10, 3) means 10 total digits of precision, with 3 of those digits being to the right of the decimal point.

CodePudding user response:

This will return 3 decimal places even you only have 2 decimals.

SELECT TO_CHAR(CAST(-2334.06 AS NUMERIC(10,3)), '9999999999990.999') AS output FROM dual;
  • Related