Symfony无法显示浮点数



我有一个用条令映射的Symfonyproduct实体。

我的专栏价格是这样定义的:

/**
* @ORMColumn(type="float", scale=2)
*/
private $price;

在PhpMyAdmin中,在我的一个产品上,我将价格定义为59.99。但当我在模板中显示它时,我不能有完整的数字,我只有59。我试过这样做:


{{  product.price|number_format(2) }}

但它显示的是59.00…垃圾堆给了我同样的东西。

有人有主意吗?

多亏了@AlexandreTrachant,我找到了解决方案,我的product.pricegetter就像

public function getPrice(): ?int
{
return $this->price;
}

所以它允许我只存储整数,而不是浮点/十进制数。把它改成浮点数,我就有了完整的十进制数。

不知道为什么要去掉小数,但我更喜欢使用decimal:类型

/**
* @ORMColumn(type="decimal", precision=10, scale=2)
*/
private $price;

最新更新