2

This is my migrations

$table->float('odd', 10, 0)->nullable();

I save odd value in db as 4.45 but it returned as 4.45000000000000017763568394002504646778106689453125
I look this post Laravel Eloquent double value stored in database returned rounded

but that is not solve my problem. Also problems only occur in server
How can solve it?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Davit Zeynalyan
  • 8,418
  • 5
  • 30
  • 55

1 Answers1

1

I know I am a little late, but maybe this can help someone.

PHP7.1 json_encode() Float Issue

TLDR

The problem is in serialize_precision in php.ini https://www.php.net/manual/en/ini.core.php

Mine was set to 100 and it caused me the same problems. Setting to -1 resolved it.

Mirko Manojlovic
  • 73
  • 1
  • 2
  • 9
  • 1
    Did you know that if a question can be answered by another answer on Stack Overflow we do not usually add a new answer? I know you don't have enough reputation to comment, but we post the link in a comment and close the question as a duplicate. – Dharman Oct 18 '20 at 13:15
  • Another reason to hate PHP. I rounded my floats using the `round` function, yet `json_encode` will mess them up. – Martin Braun Apr 26 '22 at 00:33