Jump to content

[SOLVED] only calculate before the comma


nitation

Recommended Posts

Hello people,

 

I am having problems with the comma sign in the amount field. I have a figure in my amount field that looks like this;

 

7500004

 

when i try to transfer a sum that looks like 750,0004, it will only calculate all the figures before the comma.

 

I wanna know if i have an error in my database or what.

 

my table looks like this

 

amount varchar(255);

 

do i need to change the column type to something like FLOAT, DECIMAL or what.

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/112791-solved-only-calculate-before-the-comma/
Share on other sites

This is the sql query to insert to the database

 

include ("db.php");
$sqlsub=mysql_query("insert into account_activity(userid,AccountSelector,amount_to_send)values('$afso_userid','$AccountSelector','$amount')");

 

Do i need to provide anything else?

Just try this and see if it gives you an error in regards to what the problem is.

 

$query = "INSERT INTO `account_activity` ( `userid`, `AccountSelector`, `amount_to_send` ) VALUES ( ' $afso_userid', '$AccountSelector', '$ammount' )";
$result = mysql_query($query) or trigger_error(mysql_error());

Well it looks like there are single quotes which would make me think that the calculations are being done in php but the number isn't being converted from a string. You might be able to fix it where the calculation is, but the best way would probably be to just remove the commas before putting the string in the database. I think this would work:

$sqlsub=mysql_query("insert into account_activity(userid,AccountSelector,amount_to_send)values('$afso_userid','$AccountSelector','".preg_replace(",", "", $amount)."')");

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.