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?

2
  • Can you show how you're retrieving the value from the database? Commented May 26, 2019 at 12:45
  • @RossWilson Like UserTip::find(1, ['odd']); Commented May 26, 2019 at 12:46

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Another reason to hate PHP. I rounded my floats using the round function, yet json_encode will mess them up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.