dongtingrun4973 2012-08-22 11:35
浏览 103

在php中将Integer转换为Double

I am not able to insert a field into Mysql. Input is passed from HTML form as string. I think that problem is due to type mismatch. DB type is double

And i can't able to convert it into Double or float. using floatval() or Doubleval().

usually the input is like 8 i want it convert it as 8.0

  • 写回答

2条回答 默认 最新

  • douhan4243 2012-08-22 11:37
    关注

    You can insert 8 perfectly safely into a decimal or float. It doesn't have to be 8.0 at all.

    If you are having trouble inserting the value in, it isn't the data type on your database, but another issue.

    If you post further detail, we will look into more :)

    Edit: Here is some input data into int, decimal and float types:

    mysql> create table numberTest(inty int(2), decy decimal(3,2), floaty float(3,2));
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> select * from numberTest;
    Empty set (0.00 sec)
    
    mysql> insert into numberTest values(7,7,7);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into numberTest values(7.2,7.2,7.2);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from numberTest;
    +------+------+--------+
    | inty | decy | floaty |
    +------+------+--------+
    |    7 | 7.00 |   7.00 |
    |    7 | 7.20 |   7.20 |
    +------+------+--------+
    2 rows in set (0.01 sec)
    

    If you can't insert your values, show your insert commands in PHP, it isn't the data type. You are barking up the wrong tree with this question.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作