Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Format number to two decimal places

770225Jun 22 2010 — edited Jun 22 2010
Hi All,

I've been trying to find a post similar to my question on OTN but haven't been very successful. Found [this |http://forums.oracle.com/forums/thread.jspa?messageID=4231352&#4231352] but it’s not the right solution for me.

I want to convert a number (with two decimal places) to a string but keep the trailing zeros. The number can be of any length.

So for e.g.

Number String
1234.5 1234.50
323213.1 323213.10
9876.23 9876.23

Using a format mask in with the to_char function doesn’t work for me because the results are written to a text file using UTL_FILE and I don’t want any leading white spaces.

E.g.

Select to_char(1234.40, ‘9999999.99’) from dual
TO_CHAR(1232.70,99999999.99)
----------------------------
1232.70

As you can see the to_char only works partially. It keeps the two decimal places and adds a zero but then it also hads white space to the front of the number. I could change the format mask to '9999.99' but then if the number is 12345.12 or 123.12 it wouldn't work!

Thanks!
This post has been answered by Boneist on Jun 22 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2010
Added on Jun 22 2010
4 comments
202,517 views