Home » SQL & PL/SQL » SQL & PL/SQL » zero padding decimal in oracle
zero padding decimal in oracle [message #300908] Mon, 18 February 2008 11:59 Go to next message
shalini_apk
Messages: 3
Registered: February 2008
Junior Member

i'm in need, kindly help

i want to do zero padding on the number which i have.

for eg: 12345.78 i want 4 decimals
ie 12345.7800
for eg: 12345.78 i want 3 decimals
ie 12345.780

i know only the number of decimals that can be given, with this info i need to do zero padding, i can use rpad but i dont know the total number to which we can do padding.

somebody kindly help me on this.
Re: zero padding decimal in oracle [message #300910 is a reply to message #300908] Mon, 18 February 2008 12:02 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Use the to_char function with the appropriate format mask.
Re: zero padding decimal in oracle [message #300913 is a reply to message #300910] Mon, 18 February 2008 12:09 Go to previous messageGo to next message
shalini_apk
Messages: 3
Registered: February 2008
Junior Member
to_char("12345.73",".0000");
12345.7300
to_char("12345",".0000");
12345.0000
to_char("12345.7389",".0000");
12345.7389
will i get such result?
is this the rite way to use?
Re: zero padding decimal in oracle [message #300914 is a reply to message #300913] Mon, 18 February 2008 12:15 Go to previous messageGo to next message
Michel Cadot
Messages: 68734
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Why not reading the documentation and testing instead of asking us?

By the way, string literal are enclosed by ' not ".

In addition, please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code.
Use the "Preview Message" button to verify.


Regards
Michel
Re: zero padding decimal in oracle [message #300915 is a reply to message #300913] Mon, 18 February 2008 12:17 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Almost, but ...

1) Oracle uses single quotes ('), NOT double quotes (")

2) You are missing the digits in front of the decimal point in the format mask. The way it is now any value greater than one will result in "#####".

More format mask syntaxes and examples are here



[Updated on: Mon, 18 February 2008 12:18]

Report message to a moderator

Re: zero padding decimal in oracle [message #300918 is a reply to message #300914] Mon, 18 February 2008 12:43 Go to previous messageGo to next message
shalini_apk
Messages: 3
Registered: February 2008
Junior Member
Michel - thanks for your advice.. it will be better if you are kind. i'm new to this forum.. will never use this again...
ThomasG - thanks for your timely help and kind reply
Re: zero padding decimal in oracle [message #305750 is a reply to message #300914] Tue, 11 March 2008 19:39 Go to previous messageGo to next message
msax
Messages: 1
Registered: March 2008
Location: System Analyst
Junior Member
I see that the first two bullets on the Forum Guide state:

Be polite!

Never belittle anyone for asking beginner-level questions or for their English skills.


BOTH OF WHICH, YOU HAVE VIOLATED, moderator (Michel)

[Updated on: Tue, 11 March 2008 19:40]

Report message to a moderator

Re: zero padding decimal in oracle [message #305793 is a reply to message #305750] Wed, 12 March 2008 01:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68734
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
So you do.

Regards
Michel
Re: zero padding decimal in oracle [message #305798 is a reply to message #305750] Wed, 12 March 2008 01:21 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
msax wrote on Wed, 12 March 2008 01:39
I see that the first two bullets on the Forum Guide state:

Be polite!

Never belittle anyone for asking beginner-level questions or for their English skills.


BOTH OF WHICH, YOU HAVE VIOLATED, moderator (Michel)


Exactly where did Michel
- belittle someone for asking beginner-level questions
- belittle someone for his/her English skills? (Pointing someone to the fact that Oracle uses single quotes instead of double quotes is NOT commenting on language)
Re: zero padding decimal in oracle [message #305800 is a reply to message #305793] Wed, 12 March 2008 01:23 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
Michel Cadot wrote on Wed, 12 March 2008 07:11
So you do.

Regards
Michel


Same here: Where did msax belittle anyone for asking beginner-level questions of on his/her use of English?


Both of you, quit fighting and focus (back) on the original problem.
Re: zero padding decimal in oracle [message #305804 is a reply to message #305800] Wed, 12 March 2008 01:31 Go to previous messageGo to next message
Michel Cadot
Messages: 68734
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Frank, I was just pointing to the last part in capitals and I was as short as possible to limit the annoyance, sorry to be felt compelled to add one more post.

Regards
Michel
Re: zero padding decimal in oracle [message #305843 is a reply to message #305804] Wed, 12 March 2008 03:23 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
IF NOT /forum/fa/1707/0/ THEN
EVERYONE := /forum/fa/1582/0/
/forum/fa/1604/0/
/forum/fa/3415/0/
ELSE
/forum/fa/1602/0/
/forum/fa/2944/0/
-- and even perhaps
/forum/fa/3416/0/
END IF;
Re: zero padding decimal in oracle [message #305851 is a reply to message #305843] Wed, 12 March 2008 03:48 Go to previous messageGo to next message
Michel Cadot
Messages: 68734
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
/forum/fa/1581/0/

Should be displayed each time you start a topic. Wink

Regards
Michel
Re: zero padding decimal in oracle [message #305915 is a reply to message #300908] Wed, 12 March 2008 06:00 Go to previous messageGo to next message
daniel_india
Messages: 4
Registered: March 2008
Junior Member
hi,
use below one

SELECT TO_CHAR(-10000.45,'999999.9999') "Amount"
FROM DUAL;

result:
Amount

-10000.4500
Re: zero padding decimal in oracle [message #305920 is a reply to message #300908] Wed, 12 March 2008 06:06 Go to previous messageGo to next message
mshrkshl
Messages: 247
Registered: September 2006
Location: New Delhi
Senior Member
thanks daniel,

at least you brought back to topic.

regards,
Re: zero padding decimal in oracle [message #305923 is a reply to message #305920] Wed, 12 March 2008 06:09 Go to previous messageGo to next message
Michel Cadot
Messages: 68734
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
But the answer was already given.

Regards
Michel
Re: zero padding decimal in oracle [message #305927 is a reply to message #300908] Wed, 12 March 2008 06:14 Go to previous messageGo to next message
mshrkshl
Messages: 247
Registered: September 2006
Location: New Delhi
Senior Member
but thanks was for bringing back to topic.

regards,
Re: zero padding decimal in oracle [message #305932 is a reply to message #305927] Wed, 12 March 2008 06:22 Go to previous message
Michel Cadot
Messages: 68734
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Which is closed.

Thanks for bringing away from it. Evil or Very Mad

Regards
Michel
Previous Topic: how many number of elements passed to in operator
Next Topic: Cursor problem
Goto Forum:
  


Current Time: Wed Feb 12 01:16:34 CST 2025