rugzo Posted November 16, 2008 Share Posted November 16, 2008 Hi all, i have a very strange problem by calculation. In mysql i am trying to sum one part of the table. the code --> <?php $query = mysql_query("SELECT sum(Mass) from Rapor where Agent = 'Cengiz Palabıyık' and Reason = 'yıllık izin'") ; $row = mysql_fetch_array($query) ; echo ($row['sum(Mass)']) ; ?> the result should be 46,5 but it comes as 46. There are actually 4 rows with the values 9,5 9,5 9,5 and 19. Here is a miscalculation of 0,5. I did also try it in another table where the result should be 67,5 but it comes as 66. Here are two rows with the values 57 and 9,5. Here is a miscalculation of 1,5. What could the problem be??? Thanks very much... Link to comment https://forums.phpfreaks.com/topic/132943-miscalculation-sum/ Share on other sites More sharing options...
trq Posted November 16, 2008 Share Posted November 16, 2008 9,5 is not a valid number. What field types are you using? Link to comment https://forums.phpfreaks.com/topic/132943-miscalculation-sum/#findComment-691329 Share on other sites More sharing options...
rugzo Posted November 16, 2008 Author Share Posted November 16, 2008 thx for the reply. I used varchar... Link to comment https://forums.phpfreaks.com/topic/132943-miscalculation-sum/#findComment-691382 Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2008 Share Posted November 16, 2008 After you fix the storage and format of those so that they are treated as decimal or floating point numbers, you need to get a new calculator. The sum of the values in your first example is 47.5 (not 46.5) and the sum in the second example is 66.5 (not 67.5) Link to comment https://forums.phpfreaks.com/topic/132943-miscalculation-sum/#findComment-691386 Share on other sites More sharing options...
rugzo Posted November 16, 2008 Author Share Posted November 16, 2008 Thanks very much... Link to comment https://forums.phpfreaks.com/topic/132943-miscalculation-sum/#findComment-691588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.