This code checks if the original price is numeric before performing calculations to avoid the warnings.
<?php
// Original price
$price = 5.16;
// Percentage to add
$percentage = 12;
// Check if $price is numeric before performing calculations
if (is_numeric($price)) {
// Calculate newPrice with the percentage added and limit to 2 decimals
$newPrice = round($price + ($price * $percentage / 100), 2);
// Output the result
echo "New Price: $newPrice";
} else {
// Handle the case where $price is not numeric
echo "Invalid price value";
}
?>