How can PHP classes be extended to accommodate special formatting requirements for numeric values in tables?

When working with numeric values in tables, we may need special formatting requirements such as adding currency symbols or decimal precision. One way to accommodate these requirements is by extending PHP classes to create custom formatting methods for numeric values. By creating a child class that extends the parent class with additional formatting functions, we can easily apply the desired formatting to numeric values in tables.

class NumericFormatter {
    public function formatCurrency($value) {
        return '$' . number_format($value, 2);
    }
}

class CustomNumericFormatter extends NumericFormatter {
    public function formatPercentage($value) {
        return number_format($value, 2) . '%';
    }
}

// Example usage
$numericValue = 1000;
$customFormatter = new CustomNumericFormatter();
echo $customFormatter->formatCurrency($numericValue); // Output: $1,000.00
echo $customFormatter->formatPercentage(0.75); // Output: 75.00%