Unix Technical Forum

decimal precision to string

This is a discussion on decimal precision to string within the Oracle Miscellaneous forums, part of the Oracle Database category; --> new to Oracle. function output is number and produces things like this 100 19.95 19.0005 ..00625 3.1 I need ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 12:42 PM
jobs
 
Posts: n/a
Default decimal precision to string

new to Oracle.

function output is number and produces things like this

100
19.95
19.0005
..00625
3.1


I need outputs to be reformated to format out into char(5), no decimal
point rounded to hundreth decial.. looking like this?
10000
01995
01900
00001
00310

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 12:42 PM
Mark D Powell
 
Posts: n/a
Default Re: decimal precision to string

On May 7, 3:52 pm, jobs <j...@webdos.com> wrote:
> new to Oracle.
>
> function output is number and produces things like this
>
> 100
> 19.95
> 19.0005
> .00625
> 3.1
>
> I need outputs to be reformated to format out into char(5), no decimal
> point rounded to hundreth decial.. looking like this?
> 10000
> 01995
> 01900
> 00001
> 00310


Try something like:
select to_char(round(19.0005 * 100, 3),'00009') from dual;

TO_CHA
------
01900

though i am not sure I got the rounding right. I do not think your
description of what you want and the example match up. All your
results are the number * 100 except for the .00625 one.

HTH -- Mark D Powell --


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 12:42 PM
Thorsten Kettner
 
Posts: n/a
Default Re: decimal precision to string

On 7 Mai, 22:06, Mark D Powell <Mark.Pow...@eds.com> wrote:
> On May 7, 3:52 pm, jobs <j...@webdos.com> wrote:
> > function output is number and produces things like this

>
> > 100
> > 19.95
> > 19.0005
> > .00625
> > 3.1

>
> > I need outputs to be reformated to format out into char(5), no decimal
> > point rounded to hundreth decial.. looking like this?
> > 10000
> > 01995
> > 01900
> > 00001
> > 00310

>
> Try something like:
> select to_char(round(19.0005 * 100, 3),'00009') from dual;
>
> TO_CHA
> ------
> 01900
>
> though i am not sure I got the rounding right. I do not think your
> description of what you want and the example match up. All your
> results are the number * 100 except for the .00625 one.


Yes, he/she? wants all values multiplied by 100 rounded to integers.

As you've multiplied by 100 already, you would round(value,0) instead
of round(value,3):

select to_char(round(value * 100),'00009') from dual;

And if I am not mistaken to_char does the rounding anyhow if format's
precision doesn't suffice. Hence

select to_char(value * 100,'00009') from dual;

is all you need.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 12:42 PM
Thorsten Kettner
 
Posts: n/a
Default Re: decimal precision to string

On 8 Mai, 12:01, Thorsten Kettner <thorsten.kett...@web.de> wrote:
> select to_char(round(value * 100),'00009') from dual;
> select to_char(value * 100,'00009') from dual;


Oops that was copy & paste. Format '00009' looks strange. Should be
'00000'.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:23 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com