This commit is contained in:
cjd
2026-02-05 22:22:10 +08:00
parent fef9fe0c31
commit bf3a2e6971
273 changed files with 30605 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
<?php
if (!class_exists('NumberFormatter')) {
class NumberFormatter
{
public const CURRENCY = 1;
public const DECIMAL = 2;
private string $locale;
private int $style;
public function __construct(string $locale, int $style)
{
$this->locale = $locale;
$this->style = $style;
}
public function formatCurrency(float | int | string $amount, string $currency): string
{
$value = (float) $amount;
$formatted = number_format($value, 2, '.', ',');
return $currency . ' ' . $formatted;
}
public function format(float | int | string $number): string
{
$value = (float) $number;
$decimals = (abs($value - (int) $value) > 0.000001) ? 2 : 0;
return number_format($value, $decimals, '.', ',');
}
}
}