Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Now I'm confused:

$ perl -v This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi $ perl -e 'printf "%.2f\n%.2f\n", 0.335, 1.335;' 0.34 1.33

and

C:\>perl -v This is perl, v5.8.9 built for MSWin32-x86-multi-thread (with 9 registered patches, see perl -V for more detail) C:\>perl -e "printf qq{%.2f\n%.2f\n}, 0.335, 1.335;" 0.34 1.34

Am I missing something (as usual)?

Update:

Following ikegami's suggestion, I tried increasing the precision to 40 digits, and got:

$ perl -v This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi $ perl -e 'printf "%.40f\n%.40f\n", 0.335, 1.335;' 0.3350000000000000199840144432528177276254 1.3349999999999999644728632119949907064438 C:\>perl -v This is perl, v5.8.9 built for MSWin32-x86-multi-thread (with 9 registered patches, see perl -V for more detail) C:\>perl -e "printf qq{%.40f\n%.40f\n}, 0.335, 1.335;" 0.3350000000000000200000000000000000000000 1.3350000000000000000000000000000000000000

It looks like this variation is just an artifact of 64-bit vs. 32-bit, emphasizing how you should never rely on precise results from rounding.


In reply to Re^3: sprintf rounding convention by kennethk
in thread sprintf rounding convention by jagaranga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-16 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found