Symfony2实体返回的浮点值小于db中的浮点值
所以我在我的实体中得到了这个Symfony2实体返回的浮点值小于db中的浮点值,symfony,numbers,entity,return-value,Symfony,Numbers,Entity,Return Value,所以我在我的实体中得到了这个 /** * @ORM\Column(type="float", nullable=true) * @Assert\Range( min = "-180", * max = "180") * */ protected $longitude; 当我在公共函数getLongitude()中执行此操作时 这是印刷品 float 4.5003715 但在数据库中,值是 4.500371500000028 我想不出来。有什么
/**
* @ORM\Column(type="float", nullable=true)
* @Assert\Range( min = "-180",
* max = "180")
*
*/
protected $longitude;
当我在公共函数getLongitude()中执行此操作时
这是印刷品
float 4.5003715
但在数据库中,值是
4.500371500000028
我想不出来。有什么建议吗
编辑:
更改为此,但仍然返回
float 4.5003715
float
是一种具有精度损失的类型,如果要获得精确值,请将类型更改为decimal
。比如:
@Column(type="decimal", precision=18, scale=15)
您可以将scale
添加到列定义@ORM\column(type=“float”,nullable=true,scale=15)
不会更改任何内容:(太糟糕了,添加行后是否更新了数据库架构?我更新了。然后确保值仍然足够长。尝试使用decimal
type而不是float
,例如:@ORM\Column(type=“float”,nullable=true,precision=11,scale=8)
经度范围从-180度到+180度,因此decimal(11,8)
就足够了。请记住在修改批注时清除缓存。这会导致我的数字末尾出现大量0。数字末尾的0不会更改它们的“值”,1.5等于1.500000000000I使用的精度=16,比例=15
基于示例数字4.50037150000028
。但是读取“断言范围”,如果要存储179.50037150000028
,则必须使用precision=18,scale=15。
float 4.5003715
@Column(type="decimal", precision=18, scale=15)