Php 视图中的除法和乘法-laravel
在以下html模板中,我尝试以以下形式获取百分比: 4% 但当我执行乘法和除法时,它显示为 2/50*100 我怎样才能得到我想要的结果Php 视图中的除法和乘法-laravel,php,laravel,Php,Laravel,在以下html模板中,我尝试以以下形式获取百分比: 4% 但当我执行乘法和除法时,它显示为 2/50*100 我怎样才能得到我想要的结果 <div class="card-content collapse show"> <div class="card-body"> @foreach ($items->products as $i) <div style="font-
<div class="card-content collapse show">
<div class="card-body">
@foreach ($items->products as $i)
<div style="font-size:14px">{{$i->count}}/{{$total}}*100 %</div>
@endforeach
</div>
</div>
@foreach($items->products as$i)
{{$i->count}/{{$total}*100%
@endforeach
您必须在括号内进行计算:
{{ number_format($i->count / $total * 100, 2) }}%
我不是laravel专家,但我猜您是否需要像其他代码块一样,在计算代码前面加上
@
?我认为{…}
语法可能只是为了快速显示变量?因此,它将这些变量值打印在括号内,就像您要求的那样,并将其余部分视为静态文本而不是PHP代码。