PHP calculation

html, math, php

Solution

Try casting the value to a numerical value first.

$num = (double) $responseTemp->Items->Item->CustomerReviews->AverageRating;

echo $num * 2;

See Type Juggling and String Conversion to Numbers on the PHP website for more information.

Problem

I'm trying to output a value from xml this is what I do - ``` <?php echo $responseTemp->Items->Item->CustomerReviews->AverageRating; ?> ``` This outputs 4.5, but when I change it to the code below it displays as 8. Why isn't it displaying as 9? Thanks. ``` <?php echo $responseTemp->Items->Item->CustomerReviews->AverageRating*2; ?> ```

Original source