Jump to content

Miscalculation (SUM)


rugzo

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.