Try to provide a more realistic, and complete example of your problem, keeping the code to a minimum to reproduce the behavior you're seeing. Your current example does not output anything useful for me, only the output headers (no actual values, besides "Post" values of 0 0.) This makes your problem impossible to diagnose without more relevant information.

Further, the example provided should almost always enable the use strict and use warnings pragmas. I get no fewer than 27 compilation errors using strict in your example; you should review these and in most cases correct them before requesting help as the compiler catches many possible mistakes for you.

Multiplying and adding works as described in perlop for me. Given how you reference variables you never describe in the example, it's almost surely caused by code not shown.

use strict; use warnings; my $factor = 0.5; my $base = -15; my $base2 = -8; result( "$base * $factor", $base * $factor ); result( "$base2 + $base * $factor", $base2 + $base * $factor ); # Show a result. # Pass it 2 args: # ARG1: display string to inform user about the calculation. # ARG2: displayed as a float, 2 place precision. sub result { printf "%s is: %.2f\n", shift // '', shift // 0; }


In reply to Re: Floating point hell by Apero
in thread Floating point hell by DcmbrAgnt

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.