Hi, I'm trying to convert a string to an integer, so that I can do some maths on it. The PHP code that I have is:

echo "This is the type of initial netPrice:";
echo gettype($netPrice);
echo "<br/>";
echo $netPrice. " = NET PRICE<br/>";
$test = (int)$netPrice;
echo gettype($test);
echo $test. " = Net Price as an int<br/>";

Which then outputs:

This is the type of initial netPrice:string
22 = NET PRICE
integer
0 = Net Price as an int

I was wondering why it was taking my string, that has the value of 22 and converting it to 0 rather than 22?

I was using this example in order to get my code to work:

$hundred = "100";
$divide = (int)$hundred;

And it converts the string 100 to an integer. So I was hoping someone could point out where I'm going wrong!

Thanks

Hollie
I've just tried intval but sadly that is still bringing up the value of 0 instead of 22.