【发布时间】:2021-01-08 09:52:06
【问题描述】:
我今天无缘无故地收到了这个错误,因为我的 laravel 应用程序运行良好。
我的刀片中有这个价格代码:
<li>
@php
$totalPrice = Cart::all()->sum(function ($cart){
return (int) $cart['product']->price * (int) $cart['quantity'];
})
@endphp
<span>Total price : </span><span> {{ number_format((float)$totalPrice) }}</span>
</li>
但我有这个错误:
A non well formed numeric value encountered
在这一行:
return (int) $cart['product']->price * (int) $cart['quantity'];
在此之前,我的number_format 出现此错误,在搜索后,我发现我必须使用number_format((float)$price) 并解决了,但我不知道如何解决这个错误?!
【问题讨论】:
-
如果你转储
$cart['product']->price和$cart['quantity']变量,你会得到一个数字吗?在字符串或 int 中 -
@PatricNox 它是我的返回字符串
-
你能告诉我们返回值吗?
-
string(8) "14750000", '14750000' 是价格
-
这是只是变量之一的返回值吗?如果是这样,那么您会因为逗号而收到错误。