-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Summary
Create a MoneyFormatter that uses PHP's Intl extension (NumberFormatter) for currency formatting with a clean, minimal API.
Proposed Design
The formatter should leverage NumberFormatter for locale-aware currency formatting while keeping a simple interface:
use Respect\StringFormatter\MoneyFormatter;
// Simple case - uses default locale
$formatter = new MoneyFormatter('USD');
echo $formatter->format('1234.56');
// Output: "$1,234.56"
// With custom locale
$formatter = new MoneyFormatter('BRL', 'pt_BR');
echo $formatter->format('1234.56');
// Output: "R$ 1.234,56"
// With custom precision
$formatter = new MoneyFormatter('JPY', precision: 0);
echo $formatter->format('1234.56');
// Output: "¥1,235"Constructor Signature
public function __construct(
string $currency,
string|null $locale = null,
int|null $precision = null
)$currency: ISO 4217 currency code (e.g., 'USD', 'EUR', 'BRL')$locale: Optional locale for formatting (defaults to system locale)$precision: Optional decimal precision (defaults to currency's default)
Key Features
- Intl integration: Use
NumberFormatter::CURRENCYfor all formatting - Locale-aware: Respect locale-specific formatting (symbol position, separators)
- Precision control: Override currency defaults when needed
- Error handling: Validate currency codes and throw
InvalidFormatterException - Currency validation: Use
NumberFormatterto verify valid currency codes
Questions/Decisions Needed
- Should we support currency code-only output (no symbol)?
- Should we support negative numbers with specific formatting?
- Should we format as accounting style for negatives?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels