?
Solved

Format Number Field

Posted on 2016-09-15
10
Medium Priority
?
76 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 32

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 74

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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 32

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
 
LVL 74

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 74

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 74

Accepted Solution

by:
sdstuber earned 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

741 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