How can number formatting functions like number_format or money_format be used to improve security when passing session data in PHP?

When passing session data in PHP, it is important to properly format any numerical data to prevent potential security vulnerabilities such as SQL injection or cross-site scripting attacks. Number formatting functions like number_format or money_format can be used to ensure that numerical data is properly sanitized and displayed in a secure manner.

// Example of using number_format to format session data before outputting it
$price = $_SESSION['price']; // Assume this is the price retrieved from the session data
$formatted_price = number_format($price, 2); // Format the price with 2 decimal places

echo "Price: $" . $formatted_price; // Output the formatted price securely