diff --git a/src/Illuminate/Support/Number.php b/src/Illuminate/Support/Number.php index f86e681ecb0a..49feddf71eeb 100644 --- a/src/Illuminate/Support/Number.php +++ b/src/Illuminate/Support/Number.php @@ -41,7 +41,7 @@ public static function format(int|float $number, ?string $locale = null) * @param ?string $locale * @return string|false */ - public static function toPercentage(int|float $number, int $precision = 0, ?string $locale = null) + public static function percentage(int|float $number, int $precision = 0, ?string $locale = null) { static::ensureIntlExtensionIsInstalled(); @@ -60,7 +60,7 @@ public static function toPercentage(int|float $number, int $precision = 0, ?stri * @param ?string $locale * @return string|false */ - public static function toCurrency(int|float $number, string $currency = 'USD', ?string $locale = null) + public static function currency(int|float $number, string $currency = 'USD', ?string $locale = null) { static::ensureIntlExtensionIsInstalled(); @@ -76,7 +76,7 @@ public static function toCurrency(int|float $number, string $currency = 'USD', ? * @param int $precision * @return string */ - public static function toFileSize(int|float $bytes, int $precision = 0) + public static function fileSize(int|float $bytes, int $precision = 0) { $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; diff --git a/tests/Support/SupportNumberTest.php b/tests/Support/SupportNumberTest.php index b04d0edd2f6d..73787bae682a 100644 --- a/tests/Support/SupportNumberTest.php +++ b/tests/Support/SupportNumberTest.php @@ -60,69 +60,69 @@ public function testToPercent() { $this->needsIntlExtension(); - $this->assertSame('0%', Number::toPercentage(0, precision: 0)); - $this->assertSame('0%', Number::toPercentage(0)); - $this->assertSame('1%', Number::toPercentage(1)); - $this->assertSame('10.00%', Number::toPercentage(10, precision: 2)); - $this->assertSame('100%', Number::toPercentage(100)); - $this->assertSame('100.00%', Number::toPercentage(100, precision: 2)); - - $this->assertSame('300%', Number::toPercentage(300)); - $this->assertSame('1,000%', Number::toPercentage(1000)); - - $this->assertSame('2%', Number::toPercentage(1.75)); - $this->assertSame('1.75%', Number::toPercentage(1.75, precision: 2)); - $this->assertSame('1.750%', Number::toPercentage(1.75, precision: 3)); - $this->assertSame('0%', Number::toPercentage(0.12345)); - $this->assertSame('0.12%', Number::toPercentage(0.12345, precision: 2)); - $this->assertSame('0.1235%', Number::toPercentage(0.12345, precision: 4)); + $this->assertSame('0%', Number::percentage(0, precision: 0)); + $this->assertSame('0%', Number::percentage(0)); + $this->assertSame('1%', Number::percentage(1)); + $this->assertSame('10.00%', Number::percentage(10, precision: 2)); + $this->assertSame('100%', Number::percentage(100)); + $this->assertSame('100.00%', Number::percentage(100, precision: 2)); + + $this->assertSame('300%', Number::percentage(300)); + $this->assertSame('1,000%', Number::percentage(1000)); + + $this->assertSame('2%', Number::percentage(1.75)); + $this->assertSame('1.75%', Number::percentage(1.75, precision: 2)); + $this->assertSame('1.750%', Number::percentage(1.75, precision: 3)); + $this->assertSame('0%', Number::percentage(0.12345)); + $this->assertSame('0.12%', Number::percentage(0.12345, precision: 2)); + $this->assertSame('0.1235%', Number::percentage(0.12345, precision: 4)); } public function testToCurrency() { $this->needsIntlExtension(); - $this->assertSame('$0.00', Number::toCurrency(0)); - $this->assertSame('$1.00', Number::toCurrency(1)); - $this->assertSame('$10.00', Number::toCurrency(10)); + $this->assertSame('$0.00', Number::currency(0)); + $this->assertSame('$1.00', Number::currency(1)); + $this->assertSame('$10.00', Number::currency(10)); - $this->assertSame('€0.00', Number::toCurrency(0, 'EUR')); - $this->assertSame('€1.00', Number::toCurrency(1, 'EUR')); - $this->assertSame('€10.00', Number::toCurrency(10, 'EUR')); + $this->assertSame('€0.00', Number::currency(0, 'EUR')); + $this->assertSame('€1.00', Number::currency(1, 'EUR')); + $this->assertSame('€10.00', Number::currency(10, 'EUR')); - $this->assertSame('-$5.00', Number::toCurrency(-5)); - $this->assertSame('$5.00', Number::toCurrency(5.00)); - $this->assertSame('$5.32', Number::toCurrency(5.325)); + $this->assertSame('-$5.00', Number::currency(-5)); + $this->assertSame('$5.00', Number::currency(5.00)); + $this->assertSame('$5.32', Number::currency(5.325)); } public function testToCurrencyWithDifferentLocale() { $this->needsIntlExtension(); - $this->assertSame('1,00 €', Number::toCurrency(1, 'EUR', 'de')); - $this->assertSame('1,00 $', Number::toCurrency(1, 'USD', 'de')); - $this->assertSame('1,00 £', Number::toCurrency(1, 'GBP', 'de')); + $this->assertSame('1,00 €', Number::currency(1, 'EUR', 'de')); + $this->assertSame('1,00 $', Number::currency(1, 'USD', 'de')); + $this->assertSame('1,00 £', Number::currency(1, 'GBP', 'de')); - $this->assertSame('123.456.789,12 $', Number::toCurrency(123456789.12345, 'USD', 'de')); - $this->assertSame('123.456.789,12 €', Number::toCurrency(123456789.12345, 'EUR', 'de')); - $this->assertSame('1 234,56 $US', Number::toCurrency(1234.56, 'USD', 'fr')); + $this->assertSame('123.456.789,12 $', Number::currency(123456789.12345, 'USD', 'de')); + $this->assertSame('123.456.789,12 €', Number::currency(123456789.12345, 'EUR', 'de')); + $this->assertSame('1 234,56 $US', Number::currency(1234.56, 'USD', 'fr')); } public function testBytesToHuman() { - $this->assertSame('0 B', Number::toFileSize(0)); - $this->assertSame('1 B', Number::toFileSize(1)); - $this->assertSame('1 KB', Number::toFileSize(1024)); - $this->assertSame('2 KB', Number::toFileSize(2048)); - $this->assertSame('2.00 KB', Number::toFileSize(2048, precision: 2)); - $this->assertSame('1.23 KB', Number::toFileSize(1264, precision: 2)); - $this->assertSame('1.234 KB', Number::toFileSize(1264, 3)); - $this->assertSame('5 GB', Number::toFileSize(1024 * 1024 * 1024 * 5)); - $this->assertSame('10 TB', Number::toFileSize((1024 ** 4) * 10)); - $this->assertSame('10 PB', Number::toFileSize((1024 ** 5) * 10)); - $this->assertSame('1 ZB', Number::toFileSize(1024 ** 7)); - $this->assertSame('1 YB', Number::toFileSize(1024 ** 8)); - $this->assertSame('1,024 YB', Number::toFileSize(1024 ** 9)); + $this->assertSame('0 B', Number::fileSize(0)); + $this->assertSame('1 B', Number::fileSize(1)); + $this->assertSame('1 KB', Number::fileSize(1024)); + $this->assertSame('2 KB', Number::fileSize(2048)); + $this->assertSame('2.00 KB', Number::fileSize(2048, precision: 2)); + $this->assertSame('1.23 KB', Number::fileSize(1264, precision: 2)); + $this->assertSame('1.234 KB', Number::fileSize(1264, 3)); + $this->assertSame('5 GB', Number::fileSize(1024 * 1024 * 1024 * 5)); + $this->assertSame('10 TB', Number::fileSize((1024 ** 4) * 10)); + $this->assertSame('10 PB', Number::fileSize((1024 ** 5) * 10)); + $this->assertSame('1 ZB', Number::fileSize(1024 ** 7)); + $this->assertSame('1 YB', Number::fileSize(1024 ** 8)); + $this->assertSame('1,024 YB', Number::fileSize(1024 ** 9)); } public function testToHuman()