Falko
Falko

Reputation: 23

Symfony2 entity returns float as smaller float then in db

So I got this in my entity,

/**
 * @ORM\Column(type="float", nullable=true)
 * @Assert\Range(   min = "-180",
 *                  max = "180")
 *
 */
protected $longitude;

and when I do this in the public function getLongitude()

var_dump($this->longitude); exit();

this is printed

float 4.5003715

but in the database the value is

4.500371500000028

Can't figure it out. Any tips ?


Edit:

@ORM\Column(type="float", nullable=true, precision=11, scale=8)

Changed to this, but remains returning

float 4.5003715

Upvotes: 2

Views: 157

Answers (1)

Pipe
Pipe

Reputation: 2424

float is a type with precission loss, change your type to decimal if you want to get the exact value. Something like:

@Column(type="decimal", precision=18, scale=15)

Upvotes: 1

Related Questions