Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mdp85's avatar

LARAVEL 4.1 probably issue on select float

Hi guys, on one of my site that i've builded with laravel 4.1, i've something strange with select data fetched from DB. I've some float value, like 426.98. So, now when i tried to fetch i have like some rounding around this value and it changed in 430. But i'm not using some rounding function on fetch data So why this happened ?

0 likes
4 replies
adunahay's avatar

Can you show your migration that created the float field? Is the value correct in the database?

Mdp85's avatar

I can show you, only the mysql code that migration generate.

id int(10) unsigned NOT NULL AUTO_INCREMENT, order_num int(11) NOT NULL, order_email varchar(255) COLLATE utf8_unicode_ci NOT NULL, order_shipping float NOT NULL, order_vat float NOT NULL, order_total float(8,2) NOT NULL, order_delivery_date varchar(255) COLLATE utf8_unicode_ci NOT NULL, order_state_id int(11) NOT NULL DEFAULT '0', order_invoice_mode int(11) NOT NULL DEFAULT '0', deleted_at timestamp NULL DEFAULT NULL, created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', client_id int(10) unsigned NOT NULL DEFAULT '0'

the value is order_total. On db all these values are stored correctly, but i can't understand why, after select, this happened.

I'll tried to fetch data with the Query Builder

Mdp85's avatar

Thanks. This is really strange, maybe the fault is in php.ini, or httpd.config. But i'll try decimal field.

But if i try to execute a query by console all the float fields are fetched correctly. This is more strange.

robgeorgeuk you're right, with decimal all works. Thanks again! Cheers !!

Please or to participate in this conversation.