Problem on check condition on laravel php

I have a problem on my laravel code. I want to check condition and show up using dd my code here.

$ca = floatval($sw->terminal_ca); // $sw->terminal_ca from postgresql type number(8,6) = 0.003480
$max_ca = $this->terminal_ca*(1+($this->tolerance/100)); // $this->terminal_ca from postgresql type number(16,4) = 0.0029
                                                            // $this->tolerance from postgresql type number(16,4) = 20.0000

($ca <= $max_ca));

but my result here

Problem on check condition on laravel php

not acceptable.
it should be true.
What’s wrong on my code?
How can I solve it?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I have given static values in the controller and it’s working fine.
Kindly check your type in the database from where you are fetching data dynamically.

Problem on check condition on laravel php

Method 2

I round it before comparison is ok now. Thank @El_Vanja

$ca = round($ca, 6);
$min_ca = round($min_ca, 6);

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x