Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
User
Convert a number to have 2 decimal places in Oracle
I have a number column whose values I will like to convert into a number with 2 decimal places.
For example the number 1234 should become 1234.00
I tried the formula
SELECT TO_NUMBER(TO_CHAR(1234, '9999.00')) FROM DUAL
Output is 1234
I would have prefer it to be 1234.00
The output should be in number format.
Any ideas

What I have tried:

User
Convert a number to have 2 decimal places in Oracle
I have a number column whose values I will like to convert into a number with 2 decimal places.
For example the number 1234 should become 1234.00
I tried the formula
SELECT TO_NUMBER(TO_CHAR(1234, '9999.00')) FROM DUAL
Output is 1234
I would have prefer it to be 1234.00
The output should be in number format.
Any ideas
Posted
Comments
0x01AA 12-Apr-24 8:58am    
Try this:SELECT TO_CHAR(1234, 'fm99D00')
FROM DUAL;
PIEBALDconsult 12-Apr-24 14:45pm    
Will 1.23E3 work?

1 solution

You're confusing a number with the string representation of a number.

A number is just the digits that make up the number. There is no difference between 1234 and 1234.00 - they're both the same floating-point number.

Databases shouldn't be concerned with formatting values for display. Instead, you should be storing the number in the database, and formatting it appropriately in the front-end application that displays the value to the user.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900