Php 无法在Prestashop上将Smarty中的两个变量相乘

Php 无法在Prestashop上将Smarty中的两个变量相乘,php,prestashop,smarty,Php,Prestashop,Smarty,在我的prestashop商店中,每平方英尺价格和每盒价格有两个变量。每平方英尺价格之前有货币$符号。我试图打印这两个变量的相乘值。但它总是打印0 {assign var = per_sqft_price value = $product.price} {assign var = per_box_price value = $product.features[0].value} <meta itemprop="per_sqft_price" content="{$per_sqft_pri

在我的prestashop商店中,每平方英尺价格和每盒价格有两个变量。每平方英尺价格之前有货币$符号。我试图打印这两个变量的相乘值。但它总是打印0

{assign var = per_sqft_price value = $product.price}
{assign var = per_box_price value = $product.features[0].value}

<meta itemprop="per_sqft_price" content="{$per_sqft_price|replace:'$':''}"/>
{math equation = "x * y" x = $per_sqft_price  y = $per_box_price }
请帮助我如何解决这个问题。提前感谢

请尝试以下代码:

{$result = ($per_sqft_price|intval) * ($per_box_price|intval)}
这不是一种标准方法,但可能会起作用

使用$product.price\u amount而不是$product.price,它提供无货币符号的数字价格输出。并确保$product.features[0]值也是数字,因为它可能是字符串,也可能只包含文本。此外,您还可以对变量使用intval,如:

{math equation = "x * y" x = $per_sqft_price|intval  y = $per_box_price|intval }

在我编辑了这个问题后,你能不能给每平方英尺的价格和每盒的价格加上变量。你能再检查一下吗。实际上数字格式限制了做数学运算。试着用你的方式。数学运算后仍显示为空或0。正在运行。如何将结果设置为小数点后2位?如果需要在句点{math assign='result'equation=x*y x=$per_sqft_price | floatval y=$per_box_price | floatval}{$result | number_format:2}后添加数字{