I have a variable $var with the value 1.5382 $var was parsed from a text string if i multiple this number by 2 ie $answer = ($var * 2); i get 2, php is treating $var as an integer (1). how can i prevent this and get the correct answer?
Make sure that $var really does start with "1.5382", because this is what I get:
$var="1.5382"; echo $var*2;
3.0764
Perhaps I'm old-fashioned, perhaps I'm a 'C-wannabe', but I have a tendency toward typecasting variables, particularly those used in mathematical expressions:
$var = (double)1.5382; echo $var * 2;
Though it's not necessary, it sure doesn't hurt...