Question : How do I avoid division by zero error?
Answered by : hirohito
// just use null coalescing operator
number_format((0 / (0 ?: 1))); // 0 ⊦------⊣ there is
// or if your number/decimal comes from database which is "string" data type,
// do it like this: (php-bcmatch is required)
number_format(("0.00" / ("0.000" == bcadd(0,0,3) ? "1" : "0.000"))); // 0
Source : | Last Update : Wed, 02 Aug 23