Jump to content

What could be happening here??


elentz

Recommended Posts

I have some code that updates a table in a Mysql DB. The table fields are decimal 8,2.  If I interrupt the update to the table and echo the variable $formatnet_total I get 2,395.23.  If I let it update the table I get 2 in the field.  What is happening here?

 

$sql = 'SELECT SUM((vtiger_inventoryproductrel.quantity) * (vtiger_inventoryproductrel.listprice))'
        . ' from vtiger_inventoryproductrel'
        . ' where vtiger_inventoryproductrel.id = '.$id.'';

$result = mysql_query($sql,$conn);
$mytotal = mysql_fetch_row($result);
$formatnet_total=number_format($mytotal[0],2,'.',',');

$sql4 ="Update vtiger_invoicecf SET cf_602 = '$mitax', cf_610 = '$formatnet_total' where invoicei = '$id'";
$result = mysql_query($sql4) or die(mysql_error() . "<p>With Query<br>$sql4");

 

 

Thanks for looking!

Link to comment
https://forums.phpfreaks.com/topic/90221-what-could-be-happening-here/
Share on other sites

Number parsers stop when they find a character that is not part of the data type they are looking for.

 

A coma to separate fields in a number is a human convention not a computer number convention. Only add the coma separator when you display information, not when you store it.

I checked the manual..

 

http://dev.mysql.com/doc/refman/5.0/en/precision-math-decimal-changes.html

 

It doesn't specifically state that the comma would be the escape.  But it DOES state that it only accepts integers and a "."  It used to accept a "+" or a "-" but those (along with leading zeros) are no longer accepted.

 

It's definitely that comma.  Remove it and then you should be all set.

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.