Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Division by zero error how can i get rid of it?

    hi there
    i need some help with this , it just keep giving this error here
    any ideas it how i can solve it?

    Warning: Division by zero
    ...on line xxx

    $buf .= "</tr> \n";
    $tpl->set_var('lstemitidosmes',$buf);
    $tpl->set_var('mesemissao',$totaisOrdem[count($totaisOrdem)-1]['MONTH
    ']);
    $tpl->set_var('anoemissao',$totaisOrdem[count($totaisOrdem)-1]['YEAR']);
    /*getting error on this line*/ $valorPerc = ROUND((($totaisOrdem[count($totaisOrdem)-1]['VLR']/$totaisOrdem[count($totaisOrdem)-2]['VLR'])-1)*100,2);
    $tpl->set_var('aumentonomescartdsc',(($valorPerc < 0) ? "got lower":"rised"));
    $valorPerc = ($valorPerc < 0) ? ($valorPerc * -1):$valorPerc;
    $tpl->set_var('aumentonomescart', $valorPerc );
    Last edited by learninghard; 05-03-2011 at 05:33 PM. Reason: Resolved

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You stop dividing by 0.
    PHP Code:
    if (< ($denom $totaisOrdem[count($totaisOrdem)-2]['VLR'])-1)*100,2))
    {
        
    $valorPerc ROUND((($totaisOrdem[count($totaisOrdem)-1]['VLR']/$denom;

    Don't use suppression to avoid the errors, always fix them.

    If the denominator is never supposed to be 0, you'll need to debug your code to find out why it is 0.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You stop dividing by 0.
    PHP Code:
    if (< ($denom $totaisOrdem[count($totaisOrdem)-2]['VLR'])-1)*100,2))
    {
        
    $valorPerc ROUND((($totaisOrdem[count($totaisOrdem)-1]['VLR']/$denom;

    Don't use suppression to avoid the errors, always fix them.

    If the denominator is never supposed to be 0, you'll need to debug your code to find out why it is 0.
    it worked thank you , but i created var $denom called it on if , that sentence was giving an error at multiplication here

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I don't see any problem with the multiplication (its quite rare for something that cannot evaluate to a number in PHP), though I do see bracket mismatching here. Guess I shouldn't have just cut and paste parts out of it:
    PHP Code:
    $valorPerc 0;
    if (
    < ($denom $totaisOrdem[count($totaisOrdem)-2]['VLR'])) 
    {
        
    $valorPerc ROUND((($totaisOrdem[count($totaisOrdem)-1]['VLR']/$denom)-1)*100,2);

    Ok, that looks like its right. I initialized denom before the branch since it would otherwise become null outside in the event of a non-evaluation.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •