in reply to Re: Calculations using values from two different hashes
in thread Calculations using values from two different hashes

This works brilliantly, thank you very much! Just to double check that I've understood everything here, does the "%.2f" part of the code specify that only the first two decimal places should be returned?
  • Comment on Re^2: Calculations using values from two different hashes

Replies are listed 'Best First'.
Re^3: Calculations using values from two different hashes
by syphilis (Archbishop) on Nov 25, 2017 at 13:28 UTC
    does the "%.2f" part of the code specify that only the first two decimal places should be returned?

    Yes.
    More strictly speaking the returned value will be the actual value, rounded to two decimal places in accordance with the rule "round to nearest, ties to even".
    C:\>perl -le "printf '%.2f', 0.245;" 0.24 C:\>perl -le "printf '%.2f', 0.255;" 0.26
    Cheers,
    Rob
      Ah, okay. Thanks!
Re^3: Calculations using values from two different hashes
by Discipulus (Canon) on Nov 25, 2017 at 13:34 UTC
    Hello Marie oops.. Maire,

    > Just to double check that I've understood everything here, does the "%.2f"..

    This is covered under sprintf documentation, specifically in the paragraph "precision, or maximum width".

    Anyway try it to see:

    # pay attention to MSWin32 double quotes! perl -e "printf qq($_\n),3.141592 for '%f','%.0f','%.1f','%.2f'" 3.141592 3 3.1 3.14

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Ah, thanks for the link and the example. I'm going to have a play about with that now, thanks!