in reply to Getting stranger values in subtraction

Thank you so much :)

I modified the relevant line of code as follows based on the pointers above, and it seems to have solved the anomaly:

#$session->param('CART')->{total_amount} -= $amount; $session->param('CART')->{total_amount} = sprintf "%.2f", $ses +sion->param('CART')->{total_amount} - $amount;

Do we get the same problem with addition?

Replies are listed 'Best First'.
Re^2: Getting stranger values in subtraction
by Anonymous Monk on Feb 06, 2016 at 09:20 UTC
Re^2: Getting stranger values in subtraction
by Anonymous Monk on Feb 06, 2016 at 09:06 UTC

    Addendum:

    The issue seems to surface if the arithmetic takes place in a loop, when you do the subtraction (or addition as well?) multiple times.

    I don't seem to get this problem when the subtraction happens only once in a subroutine (not in a loop).

      Have you run the code in my reply? There's no loop involved. Also, have you clicked the link provided there and read the article? It answers your question about adition clearly.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        Yes, I ran your code, and then modified mine based on it after that.

        Hmm...I am still puzzled why I haven't seen that kind of anomaly in other parts of my code that do this sort of arithmetic even though I have been testing it for weeks now.