Solved

Format Number Field

Posted on 2016-09-15
10
68 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift 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 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

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 …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

687 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