Solved

Format Number Field

Posted on 2016-09-15
10
53 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 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fill Null values 5 28
TSQL Challenge... 7 35
SQL Recursion 6 18
SQL - Simple Pivot query 8 13
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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

860 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