$val = preg_replace('/(\.[1-9]?[1-9]?)\d*/e', "rtrim('\\1', '.')", $val);
$val = 12345; => 12345 $val = 12345.6; => 12345.6 $val = 12345.67; => 12345.67 $val = 12345.6789; => 12345.67 $val = 12345.6089; => 12345.6 $val = 12345.0089; => 12345