NCONVERT Output

Peter Bateman pfbcs at hotmail.com
Sun Dec 4 14:49:33 CST 2005


Hi all:

I would to see NCONVERT have a scale optional parameter.

ie NCONVERT ( X, 6)

However , because it doesn't you have to do the scaling yourself.

define <num>  = ( 1000000 * ( NONVERT ( <string> ) ) )


What if the number of  digits after the decimal is greater than the SCALE?
It depends on the application. With IEEE float size 8 data items you have
precision to 15 digits. So if you increased the scale so that you have
more than 15 digits in total you are going to lose precision anyway.

If I am going to assign <num> to a fixed point data type I ROUND the
number before assigning it.

If convert the whole number and the fraction as two separate calls
to NCONVERT be very carefull that you have allowed for the number of
digits after the decimal.
Here I have scaled the fraction by 15 decimal places.

define  ID = index (  (string + '.') , '.' )
define s1 char * 15  = string [1 : (ID - 1) ]
define s2 char * 15  = truncate (string [ (ID + 1 ) : 15] ) + 
'00000000000000000000' &
                              if  ID < SIZE ( TRUNCATE ( string ) ) &
                      else '0'

define n1 = 1000000 * NCONVERT ( s1 )         ; scale up by 6
define n2 =  NCONVERT ( s2 ) / 1000000000   ; scale down by 9
define num = n1 + n2 if n1 > 0 &
          else    0 - ( ABSOLUTE (n1) + n2 )

To create a unscaled string from a scaled number use the FORMATNUMBER 
function.
Remember to escape your decimal character in the format.

i.e let s1='#####0"."00000'
Assume scale of 5 and that <num> is positive.
define <string> char * 20  = FORMATNUMBER ( <num>, s1 >)

Regards,
Peter Bateman
>Sorry, I was getting confused by the requirement to
>output the value with a decimal point.  What I mean is
>output the value to a file as a string value rather
>than numeric.  Instruct the program reading the file,
>e.g. Excel, to treat the column as numeric.
>
>Otherwise:
>
>DEF numberitem FLOAT = NCONVERT(textitem * 100)/100
>
>Blue
>
>--- Robert Edis <robeconsult at sbcglobal.net> wrote:
>
> > Try multipling the value for the number of decimal
> > places and then use NCONVERT.  After converting to a
> > string split the integer and decimal parts and
> > insert
> > a decimal point.  E.g. if it is dollars and cents
> > multiple by 100 before NCONVERT then output the
> > string
> > as LEFT(item,n) + '.' + RIGHT(item,2).
> >
> > Blue
> >
> > --- Al Karman <alk at liasophia.com> wrote:
> >
> > > Not sure how much traction you'll get, but...try
> > > messing with the picture
> > > clause where you're defining your fields.
> > >
> > >
> > >
> > > Al
> > >
> > > Al Karman
> > > Manager, Internet Systems
> > > lia sophia
> > >  <mailto:alk at liasophia.com> alk at liasophia.com
> > >
> > >   _____
> > >
> > > From:
> > >
> > powerh-l-bounces+alk=liasophia.com at lists.sowder.com
> > >
> >
>[mailto:powerh-l-bounces+alk=liasophia.com at lists.sowder.com]
> > > On Behalf Of
> > > John Stires
> > > Sent: Friday, December 02, 2005 9:08 AM
> > > To: powerh-l at lists.sowder.com
> > > Subject: NCONVERT Output
> > >
> > >
> > >
> > > One of my coworkers has been rather perplexed with
> > > NCONVERT.  He is
> > > attempting to convert a number with a decimal
> > > component.  Instead of getting
> > > a numeric with the decimal component still intact,
> > > he is getting in integer
> > > number.  He has tried using NUM and FLOAT for the
> > > receiving defined field.
> > > Both with the same results.
> > >
> > >
> > >
> > > The ultimate goal is to produce a value with the
> > > decimal component to save
> > > in a file.
> > >
> > >
> > >
> > > It would seem that we are missing something
> > obvious,
> > > but what???
> > >
> > >
> > >
> > > We are running on a VAX with VMS 6.2 and
> > PowerHouse
> > > version 7.10.E6.
> > >
> > >
> > >
> > > I do not believe the fact that we are using this
> > out
> > > of an RDB database
> > > would have any bearing on this.
> > >
> > >
> > >
> > > Any good ideas?
> > >
> > >
> > >
> > > Thanks,
> > >
> > > John
> > >
> > > > --
> > > = = = = = = = = = = = = = = = = = = = = = = = = =
> > =
> > > = =
> > > Mailing list: powerh-l at lists.sowder.com
> > > Subscribe: "subscribe" in message body to
> > > powerh-l-request at lists.sowder.com
> > > Unsubscribe: "unsubscribe &lt;password&gt;" in
> > > message body to powerh-l-request at lists.sowder.com
> > > http://lists.sowder.com/mailman/listinfo/powerh-l
> > > This list is closed, thus to post to the list you
> > > must be a subscriber.
> > >
> >
> >
> > Robert JM Edis
> > Principal Consultant
> > Robert Edis Consulting
> > P.O. Box 676
> > Deerfield  IL  60015
> > USA
> > 1-847-612-3863
> > RobEConsult at sbcglobal.net
> >
> >
> >
> > --
> > = = = = = = = = = = = = = = = = = = = = = = = = = =
> > = =
> > Mailing list: powerh-l at lists.sowder.com
> > Subscribe: "subscribe" in message body to
> > powerh-l-request at lists.sowder.com
> > Unsubscribe: "unsubscribe &lt;password&gt;" in
> > message body to powerh-l-request at lists.sowder.com
> > http://lists.sowder.com/mailman/listinfo/powerh-l
> > This list is closed, thus to post to the list you
> > must be a subscriber.
> >
>
>--
>= = = = = = = = = = = = = = = = = = = = = = = = = = = =
>Mailing list: powerh-l at lists.sowder.com
>Subscribe: "subscribe" in message body to powerh-l-request at lists.sowder.com
>Unsubscribe: "unsubscribe &lt;password&gt;" in message body to 
>powerh-l-request at lists.sowder.com
>http://lists.sowder.com/mailman/listinfo/powerh-l
>This list is closed, thus to post to the list you must be a subscriber.

_________________________________________________________________
Scan and help eliminate destructive viruses from your inbound and outbound 
e-mail and attachments. 
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines 
  Start enjoying all the benefits of MSN® Premium right now and get the 
first two months FREE*.



More information about the powerh-l mailing list