[英]SQL / PHP converting a string to float or int
我有这个SQL查询..
select i.invoiceid as transactionid, i.date, i.total,
'invoice' as transaction_type
from invoice
我在php中运行它并在foreach循环中回显总数,就像这样....
echo gettype($row['total']) . "<br/>";
并且所有总计都返回了string
如何将我的sql查询中的i.total转换为int或float?
我试过了
convert(int, i.total)
那不起作用:(
php将所有内容(不是数组/字典)作为字符串处理,除非您明确告诉它不要使用类似(int)$row['total']
。
http://php.net/manual/en/language.types.string.php#language.types.string.conversion
你可以试试
select i.invoiceid as transactionid, i.date, CAST(i.total as int) as total,
'invoice' as transaction_type
from invoice
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.