in reply to A simple rounding question, but can't get it!

The code you post, appears correct. Maybe you should post the code snippet itself. Most likely something else going on.
You also neglect to say what it does produce.
perl -e 'my $e="20.875"; my $r=sprintf("%.2f",$e);print $r'
prints 20.88

-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: A simple rounding question, but can't get it!
by DippinPete (Initiate) on Feb 01, 2002 at 04:06 UTC
    if ($coupon_style eq "A" && $subtotal-$acoup_not_allowed_for_this_part + >= $must_spend) { $take_off_this_much = ($coupon_amount/100) * ($subtotal-$acoup_n +ot_allowed_for_this_part); $a_take_off_this_much = sprintf ("%.2f", $take_off_this_much); $b_take_off_this_much = &display_price($a_take_off_this_much); $coup_work= sprintf("%.2f", $take_off_this_much); $rooker = sprintf ("%.2f", $take_off_this_much); $a1_num_grand_total = sprintf ("%.2f", $num_grand_total); $num_grand_total = $a1_num_grand_total; $fiddler = ($num_grand_total - $coup_work); $a_fiddler = &format_price($fiddler); $b_fiddler = &display_price($a_fiddler);
    $a_take_off_this_much is what we are looking at here, say the actual number is 1.085, it returns 1.08 (bad).

    I'm not sure I understand the second reply... (sorry, I'm quite new at this).

    Thanks again,

    Pete

    Edit by tye

      Need to use <code></code> tags around your code.

      -Lee

      "To be civilized is to deny one's nature."