I have done this calculation:
$number = round(count($exc)/ count($grades),2,PHP_ROUND_HALF_UP);
When save,I have to save it into a field of an existing table which is a longtext type. The numbers got saved but become very long, something like 0.200000000000000011102230246251565404236316680908203125
I think this might cause extra db storage. When I query the numbers, they are still rounded as 2 digital. So, that’s an extra converting job. I would like to learn how to save those numbers as rounded number?
You can use PHP sprintf function coupled with format specifier like so:
If you need more info about that take a look at sprintf PHP documentation here https://www.php.net/manual/en/function.sprintf.php .