douxiuyi6529 2012-05-02 19:36
浏览 227

SQL / PHP将字符串转换为float或int

I have this sql query..

select i.invoiceid as transactionid, i.date, i.total, 
'invoice' as transaction_type
from invoice

and I ran it in php and echo out the total in a foreach loop like so....

echo gettype($row['total']) . "<br/>";

and all the totals returned string

how would I convert the i.total in my sql query to int or float?

i've tried

convert(int, i.total)

and that didnt work :(

  • 写回答

2条回答

  • douyingmou1389 2012-05-02 19:40
    关注

    You could try

    select i.invoiceid as transactionid, i.date, CAST(i.total as int) as total, 
    'invoice' as transaction_type
    from invoice
    
    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn