doufen3091 2011-09-19 11:18
浏览 12
已采纳

我正在添加一条包含价格9.50英镑的记录,并且它正在向上/向下舍入?

I have a simple insert record 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"));
  • 写回答

1条回答 默认 最新

  • doufeinai6081 2011-09-19 11:23
    关注

    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").

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?