What are the potential pitfalls of using str_replace to replace commas with periods in decimal inputs before inserting them into a database?

Replacing commas with periods in decimal inputs using str_replace can lead to incorrect data if the input contains thousands separators or if the input is in a different decimal format. To accurately handle decimal inputs, it is better to use PHP's number_format function to ensure proper formatting before inserting them into the database.

// Example of using number_format to handle decimal inputs before inserting into the database
$input = "1,234.56";
$cleaned_input = number_format((float)str_replace(',', '', $input), 2, '.', '');

// Insert $cleaned_input into the database