开发者

I'm adding a record which contains a price, £9.50, and it's being rounded up/down?

开发者 https://www.devze.com 2023-04-06 08:24 出处:网络
I have a simple insert record 开发者_Python百科to add an item to a recordset. The data field for price is set to decimal and when the price field is sent e.g. 9.50 it appears in the database as 9.00.

I have a simple insert record 开发者_Python百科to add an item to a recordset. The data field for price is set to decimal and when the price field is sent e.g. 9.50 it appears in the database as 9.00. Why?

Here's the code from the php insert statement

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO buying (`user`, items, price) VALUES (%s, %s, %s)",
                   GetSQLValueString($_POST['user'], "text"),
                   GetSQLValueString($_POST['items'], "int"),
                   GetSQLValueString($_POST['price'], "int"));


From the manual:

The declaration syntax for a DECIMAL column is DECIMAL(M,D).

So, what did you specify for D? Sounds like perhaps 0.


Edit

I don't know what GetSQLValueString is, but you wrote GetSQLValueString($_POST['items'], "int") which seems to imply that you're creating an integer, no?

If it's this function, I think you clearly meant GetSQLValueString($_POST['items'], "double").

0

精彩评论

暂无评论...
验证码 换一张
取 消