Page 1 of 1

How to convert string into numbers

Posted: Thu Jul 29, 2010 11:10 am
by infomamun
Hi there
I want to convert a string into number which I got from scrapping. But problem is if the string contains decimal point it is automatically converted as round number.


$str = <? echo "10.42" ?>;
<? echo (int)$str; ?>

but the output is 10.

How to convert is as 10.42 instead 10 by a single line of code?

Re: How to convert string into numbers

Posted: Thu Jul 29, 2010 11:20 am
by Darhazer
use (float) instead of (int)

Re: How to convert string into numbers

Posted: Fri Jul 30, 2010 10:02 pm
by infomamun
Thanks a lot.