Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Rounding

by uwevoelker (Pilgrim)
on Sep 23, 2002 at 09:13 UTC ( #200049=note: print w/replies, xml ) Need Help??


in reply to Rounding

$rounded=sprintf ("%.1f",$r+.05);
This solves your problem :-)

Replies are listed 'Best First'.
Re^2: Rounding
by Aristotle (Chancellor) on Sep 23, 2002 at 09:26 UTC
    That causes 1.3 to be rounded to 2.0. I don't believe that's what the poster wanted.

    Makeshifts last the longest.

      No, it does not.
      I ran
      $r = 1.3; print $r,"\n"; $rounded=sprintf ("%.1f",$r+.05); print $rounded,"\n";
      and got
      perl -w round.pl 1.3 1.4
      Did you miss a 0 after the decimal? or is there some other behaviour I a missing.
        If you look a bit further,  1.4 + 0.05 prints as 1.4, not 1.5
        Argh. Sorry, was in a hurry and read to carelessly and then didn't notice the extra 0 even after tripplechecking - I didn't think anyone could be that stupid. Turns out my instinct was right, and you were too. Sorry again.

        Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2022-05-28 21:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?