I am currently updating some code in our backend system since the mobile app has already been deployed and we don’t have a mobile app developer at the moment.
$fees = $this->fees;
$stant_fee = 0;
foreach($fees as $fee){
if($fee->is_override){
$stant_fee+=$fee->override_amount;
}else{
$stant_fee+= $fee->commission_fee;
}
}
return round((double) $stant_fee + (double) $this->amount_per_kwh, 2);
The code works well, always returning 2 decimal places. However, if the float ends with a 0, PHP cancels the last 0, returning only 1 decimal place. For example, if the total is 0.60, it returns 0.6. How can I ensure it always returns 2 decimal places?
I have already tried using ‘number_format’ and ‘sprintf’, but the data type returned is a string. When I cast it back to a float, it still cancels the 0, returning 0.6 again.
I also tried addbc, ceil and round but still it return 1 decimal only.