How can one convert a string to a float in PHP before using the number_format function?

When using the number_format function in PHP, it requires a numeric value as input. If the input is a string, we need to convert it to a float before passing it to number_format. This can be achieved by using the floatval function in PHP, which converts a string to a float.

// Convert a string to a float before using number_format
$string_number = "123.45";
$float_number = floatval($string_number);
$formatted_number = number_format($float_number, 2);

echo $formatted_number; // Output: 123.45