0

I have two variables which is as follows:

$ccharge = ($user_info[0]['charge']) - ($get_exam[0]['price']);

But it results -150000.

Both numbers are 150000 which should result 0, but it doesn't. Is this a familiar issue?

I have found the issue which is related to arrays. I have assigned them to simple variables and it has worked. But I want to know for my future projects.

why such formula causes problems?

2
  • 2
    Are the values stored as strings? Commented Nov 9, 2013 at 12:58
  • 2
    Use var_dump on each value and it should be clear as to what's wrong. Commented Nov 9, 2013 at 12:59

1 Answer 1

1

try this

 $ccharge = ((float)$user_info[0]['charge']) - ((float)$get_exam[0]['price']);
Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't explain why the unexpected result occurs.
this will cast it to float no matter string or int.
Why would you want it casted to float?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.