$variable = '5,25'; if (strpos($variable, ',')) { $variable = str_replace(array('.',','), array('','.'), $variable); } $variable = number_format($variable, 2, '.', '');