【发布时间】:2012-09-16 19:21:15
【问题描述】:
我经常尝试将字符串转换为整数或将两个整数相乘。我无法将字符串转换为整数,因为它导致我变成布尔值(当我使用 var_dump 时)。我可以转换字符串中的另一个整数,但我无法将它相乘。
我有这个:
<? $fees=$commerce->cart->get_total();
$payfee = str_replace(' €', '', $fees);
$payfee = str_replace(',','', $payfee); //this is the string
$fee = 0.025;
$paypal = $payfee * $fee; //this thing is not working
?>
我尝试将支付费用转换为整数,但仍然无法正常工作。我以前做过这样的事情并且效果很好,但这次不行。
任何帮助将不胜感激。
P.S 感谢整个 stackoverflow.com 社区,他们之前曾多次帮助过我。
【问题讨论】:
-
有没有办法得到纯数字的总数,没有格式化?如果是这样:疯狂!
-
@deceze 有什么想法吗?我以前做过这样的事情并且没有问题。为什么我需要格式化?我尝试格式化,但也许我做错了......
-
我不知道。那是什么推车系统?如果是第三方系统,请阅读有关如何获取原始数字的文档。否则,我们需要查看您正在使用的确切数据。
-
@demlasjr 我之前关于注册用户数的回复 - 但是 - 查看 WooCommerce API,我认为您想要的是
$paypal = $commerce->cart->total * 0.025、as the$totalvalue in their class is afloatand not a string -
除了@h2o 的建议之外,在我看来,这应该集成到支付处理器类之一中,并且可能已经集成到 Paypal 组件中。我没有深入研究它以提供更多细节。
标签: php string int woocommerce