Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

A bug of sprintf or not?

by pysome (Scribe)
on Oct 20, 2008 at 09:36 UTC ( #718178=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use warnings;
    use strict;
    ...
    my $price2   = sprintf("%.0f",100.50);
    print "$price1\n";  # price1  has rounded
    print "$price2\n";  # but price2 hasn't , Why?
    
  2. or download this
    sub round {
      my $f = @_;
      return int($f + .5);
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2023-06-07 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (29 votes). Check out past polls.

    Notices?