Kathy Wilson wrote:
> 
> When last I wrote, I was having trouble with all the zero's dropping out
> when going from Service Pack 3 to Service Pack 6 on an Windows NT pc.
> 
> I have managed to get the sprintf statement to show the 00 on the right
> side, but still having trouble with the zero's dropping out on the left side
> of the decimal place, i.e. you have 250.00 it comes out 25.00, 500.00 comes
> out as 5.00.   I'm at a loss what to do.  I've been reading and there's
> something to do with local pc's and scalar and awk and what their set too,
> but I have no idea where to look.
>

I doubt this has anything to do with sprintf().  You can try the
following:

    my $d = 500.00;
    my $s = sprintf("%.2f", $d);
    print "s=$s\n";

I expect you will see

    s=500.00

See the code below.
 
> Can someone look at this sprintf script and give me an idea as to how to
> type it to have the  00 show up on the left side.   Any suggestions would be
> appreciated.
> 
> # Output the records to the file.
> $RECNUM = 0;
> $RECCOUNT = 0;
> while(! $RS->EOF) {
> 
>         for ( $i = 0; $i < $Count; $i++ )
>         {
>                 $tmp = $RS->Fields($i)->value;
>                 $tmp =~ s/\s+$//;       # trim trailing white space
>                 $amt = $tmp;
> 
>                 # No datachecking here!  To turn this off, set the next line
> to "OFF";
>                 # This formats the SECOND field in the array (gotten from
> the database) to a
>                 # currency format.
> I think this is where my problem is:
>                         $DO_THIS_THING = "ON";
>                         if( $i == 1 && $DO_THIS_THING eq 'ON' )
>                         {
>                                 $amt = sprintf( "%.2f", $tmp );
>                         }

Change the above code to this

        {
        $amt = sprintf( "%.2f", $tmp );
        
        print "input=<$tmp> output=<$amt>\n";
        print "input len=", length($tmp), " output len=", length($amt), "\n"; 
        }

It is important that the <> be around each value.  Repost with the
results with this print added.  I would suspect the most likely causes
is that $tmp is actually 5 rather than 500 or that you have a bug in the
perl version you are using.

If the first case then you might want to adjust the data appropriately. 
If the second then either get a newer version of perl or adjust the
script to account for the bug.

> 
>                 # End Sir stuff
>                 ###
> 
>                 print OUT $amt;         #$RS->Fields($i)->value;
>                 print OUT "$FDELIM";
>         }
> 
>         print OUT "$date\t$cid\t$caccount\t$ctype\tSJC AR
> Batch\t$IDENT\t\t\t"    ;
>         print OUT "$RDELIM";
>         $RECNUM++;
>         $RECCOUNT++;
>         if ( $RECNUM == 10) {
>                 print ".";
>                 $RECNUM = 0;
>         }
>         $RS->MoveNext
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to