Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: How to calculate the sum of columns to be equal to 100?

by Laurent_R (Prior)
on Aug 15, 2013 at 18:03 UTC ( #1049636=note: print w/ replies, xml ) Need Help??


in reply to Re^3: How to calculate the sum of columns to be equal to 100?
in thread How to calculate the sum of columns to be equal to 100?

I read it originally in the documentation of the standard C library. You can certainly find the IEEE standard on this.

Strangely, your "trick" with the format does not work for me on 5.14.2:

$ perl -wE 'printf qq[%9f\t%.0f\t%2.0f\n], ($_ + 0.5) x 3 for 0 .. 10; +' 0.500000 0 0 1.500000 2 2 2.500000 2 2 3.500000 4 4 4.500000 4 4 5.500000 6 6 6.500000 6 6 7.500000 8 8 8.500000 8 8 9.500000 10 10 10.500000 10 10


Comment on Re^4: How to calculate the sum of columns to be equal to 100?
Download Code
Re^5: How to calculate the sum of columns to be equal to 100?
by Athanasius (Abbot) on Aug 16, 2013 at 02:27 UTC

    The trick works for me on DWIM Perl 5.14.2:

    11:55 >perl -wE "printf qq[%9f\t%.0f\t%2.0f\n], ($_ + 0.5) x 3 for 0 . +. 10;" 0.500000 0 1 1.500000 2 2 2.500000 2 3 3.500000 4 4 4.500000 4 5 5.500000 6 6 6.500000 6 7 7.500000 8 8 8.500000 8 9 9.500000 10 10 10.500000 10 11 11:55 >perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x +86-multi-thread

    Likewise on my 3 Strawberry Perls:

    • This is perl, v5.10.1 (*) built for MSWin32-x86-multi-thread
    • This is perl 5, version 16, subversion 0 (v5.16.0) built for MSWin32-x86-multi-thread-64int
    • This is perl 5, version 18, subversion 0 (v5.18.0) built for MSWin32-x86-multi-thread-64int

    I’m running under Windows Vista 32-bit. So it seems that Perl’s printf behaves differently under Windows. No mention of this in perlport or perlwin32, though. Strange.

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2015-07-03 11:42 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 (51 votes), past polls