Skip to content

Commit d2e68b4

Browse files
committed
Merge branch 't/71db44f9'
2 parents 71db44f + f49e60f commit d2e68b4

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/FloatCmp.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111

1212
use function bccomp;
1313
use function floatval;
14-
use function floor;
1514
use function function_exists;
16-
use function log10;
17-
use function max;
18-
use function sprintf;
19-
use function substr;
15+
use function number_format;
2016

2117
class FloatCmp
2218
{
19+
public const DECIMAL_SEPARATOR = '.';
20+
2321
/**
2422
* @param float $a
2523
* @param float $b
@@ -57,14 +55,11 @@ private static function strval(
5755
float $value,
5856
int $scale
5957
): string {
60-
/** @var string $format */
61-
$format = sprintf(
62-
'%%.%dF',
63-
max($scale - floor(log10($value)), 0) + 1
58+
return number_format(
59+
$value,
60+
$scale,
61+
self::DECIMAL_SEPARATOR,
62+
''
6463
);
65-
66-
/** @var string $result */
67-
$result = sprintf($format, $value);
68-
return substr($result, 0, -1);
6964
}
7065
}

0 commit comments

Comments
 (0)