How can one ensure that formatted numbers can still be used for calculations in PHP?

When dealing with formatted numbers in PHP, it's important to remove any non-numeric characters before using them in calculations. This can be achieved by using the PHP function `preg_replace` to strip out any commas, spaces, or other formatting characters from the number string. Once the number is cleaned up, it can be safely used in mathematical operations.

// Example code to clean up a formatted number for calculations
$number = '$1,234.56'; // Example formatted number
$cleaned_number = preg_replace('/[^0-9.]/', '', $number); // Remove non-numeric characters
$calculation_result = floatval($cleaned_number) * 2; // Perform calculation with cleaned number
echo $calculation_result; // Output the result