I keep getting division by 0 error in php.
I am currently using the following:
$ratio = 1/$rate["rate"];
the value $rate[“rate”] is 0.827 (a value returned from a feed)
Please can anyone help with this.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
if you’re getting a division by 0 error,
$rate['rate']is most certainly or equivalent to 0. More likely than not,$rate['rate']isn’t getting set at all, and thusly you’re trying to divide by an undefined value which is being cast to 0 for division.To be sure, do a
var_dump($rate['rate'])to see what it is.Whenever you’re doing a division operation that depends on a user input, I’d recommend validating the user input before attempting the division.
See this code work on tehplayground.com