Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Wrong calculations in for loop

by Athanasius (Abbot)
on Aug 22, 2012 at 13:22 UTC ( #989035=note: print w/ replies, xml ) Need Help??


in reply to Re: Wrong calculations in for loop
in thread Wrong calculations in for loop

OK, but getting the same result in Perl 5 is almost as easy:

#! perl use strict; use warnings; my $zmax = 60; # Maximum depth in your model my $dz = 0.05; # Grid spacing in z-direction print +($_ * $dz), "\n" for (0 .. int(($zmax / 0.05) + 0.5));

:-)

Athanasius <°(((><contra mundum


Comment on Re^2: Wrong calculations in for loop
Download Code
Replies are listed 'Best First'.
Re^3: Wrong calculations in for loop
by SuicideJunkie (Vicar) on Aug 22, 2012 at 20:31 UTC

    Or even simpler, just change the print to printf

    my $zmax = 60; # Maximum depth in your model my $dz = 0.05; # Grid spacing in z-direction for (my $i=0; $i <= $zmax; $i = $i+$dz) { printf("%.2f\n", $i); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989035]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2015-07-29 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls