number_format round php code example
Example 1: php number format
$num = 12345.6789;
echo number_format($num, 2, '.', '') //12345.67
echo number_format($num, 3, ',', '.') //12.345,678
Example 2: php round decimal
$value = 1.23456789;
$rounded_value = round($value, 2);
// 2 is the precision here we will get 1.23
Example 3: php number format without rounding
function cutNum($num, $precision = 2) {
return floor($num) . substr(str_replace(floor($num), '', $num), 0, $precision + 1);
}