douyan8772 2012-08-29 16:39
浏览 6

我应该使用哪种SQL类型来输入值4.865472349

PHP runs a script that correctly calculates a value. When I echo that value out it comes out as 4.865472349

Then a simple update script is used to enter the value into my database.

$query = "UPDATE members
     SET rating = $r 
     WHERE username = '$username'";
mysql_query($query);

When I do this, the value that is entered into the database is 5.

If I replace $r in the previous formula with 4.865472349 directly, it produces the same result.

Clearly this is because my SQL type was set to "integer"

But Im not sure what to change it to in order to fix this issue. Any help?

  • 写回答

4条回答 默认 最新

  • douqixia7942 2012-08-29 16:43
    关注

    You probably should use DOUBLE. It has the same precision and range as floating point numbers in PHP (in most configurations).

    To switch the type using PHPMyAdmin:

    1. Click on the table
    2. Click on structure
    3. Click on Change (the pencil icon) beside rating
    4. Under "Type" select the option "DOUBLE"
    5. Hit Save
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数