How can PHP developers convert decimal numbers with commas to periods for database storage while preserving the decimal values?

When storing decimal numbers with commas in a database, it is important to convert them to periods for proper storage. One way to achieve this is by using the str_replace function in PHP to replace commas with periods while preserving the decimal values. This can be done by first converting the number to a string, replacing the commas with periods, and then casting it back to a float for storage in the database.

$number_with_commas = "1,234.56";
$number_with_periods = (float) str_replace(",", ".", $number_with_commas);

// $number_with_periods now contains the decimal number with commas converted to periods
// Store $number_with_periods in the database