Код: Выделить всё
There was 1 failure:
1) App\StudioIntern\FormatServiceTest::testNumberToPercent
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'50 %'
+'50 %'
Код: Выделить всё
public static function numberToPercent(float $value): string
{
$percent_formatter = \NumberFormatter::create('de_DE', \NumberFormatter::PERCENT);
return $percent_formatter->format($value);
}
Код: Выделить всё
$this->assertEquals('50 %', FormatService::numberToPercent(0.5));
Код: Выделить всё
php > $percent_formatter = \NumberFormatter::create('de_DE', \NumberFormatter::PERCENT);
php > $value1 = $percent_formatter->format('0.5');
php > $value2 = '50 %';
php > echo $value1;
50 %
php > echo $value2;
50 %
php > echo ($value1 === $value2) ? 'equal' : 'not equal';
not equal
Подробнее здесь: https://stackoverflow.com/questions/792 ... e-but-isnt
Мобильная версия