Tuesday, 17 September 2013

Can't update DOUBLE field in SQL database, getting rounded

Can't update DOUBLE field in SQL database, getting rounded

Every time a user rates someone else, all of the ratings for that person
get averaged, and the average gets stored in the database as a DOUBLE. The
problem is, the rating appears to be rounded down after updating.
$totalavg = (float)((float)$ratingtotal/(float)$numratings);
echo $totalavg;
queryDB("UPDATE rated_users
SET user_avg='$totalavg'
WHERE user_name='$rated';");
I have 3 ratings for the test user I'm working on, a 5.0 and two 4.5s.
However, it appears to be forced on 5, despite the fact that it should be
a 4.667. Can anyone offer their assistance?
EDIT: Length/Values of user_avg is 10,0

No comments:

Post a Comment