Solved

Format Number Field

Posted on 2016-09-15
10
39 Views
Last Modified: 2016-09-21
I have a field that is set up as a number 13,4.
I need to format it so that it looks like the following: 9999999V99.

I was trying to use the following formula, but its not working:
to_char(emp.pro_rate_total),999999999)

Any suggestions on how I can get this?
0
Comment
Question by:metalteck
  • 4
  • 4
  • 2
10 Comments
 
LVL 31

Expert Comment

by:awking00
ID: 41800316
Can you post some sample numbers from your number(13,4) field and what you would expect them to look like after you've formatted them?
0
 

Author Comment

by:metalteck
ID: 41800334
Here are some example:
33009.6
0
91936
40996.8
85009.6
37999.52
27768
86008
56.16
40809.6
50003.2
119995.2
47840
98342.4
94536
60008
54038.4
29993.6
78000
73507.2
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 41800339
to_char(emp.pro_rate_total,'fm9999999d99','NLS_NUMERIC_CHARACTERS = ''V ''')

you didn't specify a grouping character so I made it a space (' ')
0
 
LVL 31

Expert Comment

by:awking00
ID: 41800407
The examples are fine, but how do you each of them to appear after formatting? sdstuber has shown you how to replace the decimal point with the "V" and round to two decimals and that might be all you need.
0
 

Author Comment

by:metalteck
ID: 41800529
The expected result, regardless of the value is that each value needs to be 9 characters long without any leading 0s.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 73

Expert Comment

by:sdstuber
ID: 41800544
does that mean you want leading spaces or does that mean you want trailing zeros?

or does that mean something else?
if you supply only 56.16,  that's only 5 characters.

What and where do you want the other 4 characters to be?
0
 

Author Comment

by:metalteck
ID: 41800559
Yes, I would need leading spaces since it needs to be right justified.
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 41800588
so you want trailing zeroes for values like these?  If so, do you want it to always be 2 digits after the decimal? If not, please be specific.

0
85009.6
86008

this really would be a faster process if you supplied both the input and the expected output
0
 

Author Comment

by:metalteck
ID: 41800601
Yes, I would like for 2 digits after the decimal.
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 41800688
unfortunately, to_char leaves a space for a minus sign if the number is negative.
So, to_char ends up returning a string one character too long, so you need substr to get it exactly 9 long.
Removing a 9 from the format won't do it, because then longer numbers won't fit

This works for your sample data.

substr(to_char(emp.pro_rate_total,'999999d99','NLS_NUMERIC_CHARACTERS = ''V '''),-9)

Open in new window


you might want to try
SUBSTR(TO_CHAR(emp.pro_rate_total, '999990d99', 'NLS_NUMERIC_CHARACTERS = ''V '''), -9)

Open in new window


so your 0 value will have digit to the left of the V
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now