i have value in php variable like that
$var=\'2.500000550\';
echo $var
what i want is to delete all decimal points after 2 digits.
All of the solutions which use number_format are wrong because number_format performs rounding.
The function below should work on all numbers, you can specify the decimal separator for those countries which use ','.
function truncate_decimal($number, $truncate_decimal_length = 2, $decimal_character = '.', $thousands_character = '') {
$number = explode($decimal_character, $number);
$number[1] = substr($number[1], 0, $truncate_decimal_length);
$number_truncated = implode($decimal_character, $number);
return number_format($number_truncated, $truncate_decimal_length, $decimal_character, $thousands_character);
}