I have this object:
{
timestamp:2021-09-10T08:30:00Z,
keys:[
{usage_point_id:24329232979894,key:69},
{usage_point_id:24327496366232,key:7.4},
{usage_point_id:30002431659877,key:0},
{usage_point_id:24348769886471,key:1.3755},
{usage_point_id:24328075237474,key:10.4},
{usage_point_id:24348480450805,key:11.8245}
]
}
I want to make sure that the sum of all those percent is not superior to 100. So, I do:
$measuresByTS->each(function ($measures) {
if ($measures['keys']->sum('key') > 100) {
dump("sum is superior to 100 : ". $measures['keys']->sum('key'));
}
});
Weird thing is in my case, I manually checked the sum and it is equal to 100, not superior. In this case, in my code, it will display:
"sum is superior to 100 : 100"
I tried to cast $measures['keys']->sum('key')
to float
, but it is not working.
Anybody knows why this is happening ?
Using Laravel 8 / PHP 8