Re: converting to FLOATING_POINT..



Thanks Rex:
Please help me in knowing one more related thing. I have from this script of mine an output like this:
0.0 0.00
0.4 60.37
0.8 106.29
1.2 140.56
1.6 168.75
2.0 186.37
2.4 207.82
2.8 225.45
3.2 235.88
3.6 245.55
4.0 250.61
4.4 260.06
4.8 264.60
5.2 271.11
5.6 272.90
6.0 275.62
6.4 283.33
6.8 283.55
7.2 284.58
7.6 285.22
8.0 287.51
8.4 290.38
8.8 294.09
9.2 297.01
9.6 296.16
10.0 291.57
10.4 292.88
10.8 297.28
11.2 301.13


I want to see it formatted more beautifully, i.e. decimals under decimals. How do we get that. My script is:

use strict;
use warnings;

my $mdout_file = "mdout.txt";

my $mdout_xtemp_file = "temp.txt";


open IN, $mdout_file or die; open OUT, ">$mdout_xtemp_file" or die;


while (<IN>)

                      {

                  if ($_ =~ ( /TEMP/ ))

                            {

                            my $time = (substr($_, 30, 14));
                            $time =~ s/\s//g;
                            my $temp = (substr($_, 53, 10));
                            $temp =~ s/\s//g;

			     $time = sprintf("%0.1f", ($time * 2));


foreach ($time) { print OUT $time ; print OUT " "; foreach ($temp) { print OUT $temp; print OUT "\n"; } }

                            }

                      }

Thanks again!
Cheers
v







From: Rex Rex <perlicious@xxxxxxxxx>
To: Vineet Pande <pande_vineet@xxxxxxxxxxx>
CC: beginners@xxxxxxxx
Subject: Re: converting to FLOATING_POINT..
Date: Wed, 17 Aug 2005 11:14:02 -0400

Replace,

$time = ($time * 2.0);

to

$time = sprintf("%0.2f", ($time * 2));

That should do it.

perldoc -f sprintf

-- Rex

On 8/17/05, Vineet Pande <pande_vineet@xxxxxxxxxxx> wrote:
> Hi:
>
> In the following piece of script, I would like to convert the $time after *
> by 2.0 to floating point, for instance i want 0*2 to be printed as 0.0; How
> to do that?
>
>
> if ($_ =~ ( /TEMP/ ))
>
> {
>
> my $time = (substr($_, 30, 14));
> $time =~ s/\s//g;
> my $temp = (substr($_, 53, 10));
> $temp =~ s/\s//g;
> $time = ($time * 2.0);
> $time = ?????????????????#convert to floatpoint
> foreach ($time)
> {
> print OUT $time ;
> print OUT " ";
> foreach ($temp) {
> print OUT $temp;
> print OUT "\n";
> }
> }
>
> }
>
>
> cheerio
> vineet
>
> _________________________________________________________________
> FREE pop-up blocking with the new MSN Toolbar - get it now!
> http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
> For additional commands, e-mail: beginners-help@xxxxxxxx
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


.



Relevant Pages