3

Laravel truncate value of type double.

The value 3.539363636363637 is showed as 3.5393636363636

I do this so:

$e=Enrollment::find(173);
dd($e->value);
// show 3.5393636363636

In phpmyadmin the value is correct 3.539363636363637

2 Answers 2

3

Laravel is not truncating your data; PHP is. The default precision for floating point numbers in PHP is 14 significant digits. If you were to raise your precision up to 16 digits, your value would print fine.

PhpMyAdmin is showing the "correct" value because it treats it as a string; it never actually converts it to a floating point number.

ini_set('precision', 16);

$e=Enrollment::find(173);
dd($e->value);
// would show 3.539363636363637 (all 16 significant digits)
Sign up to request clarification or add additional context in comments.

Comments

0

Try changing from double to decimal, I can remember someone having some issues with double types and rounding at some point so it might be worth a shot.

Comments

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.