File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change 11
11
12
12
use function bccomp ;
13
13
use function floatval ;
14
- use function floor ;
15
14
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 ;
20
16
21
17
class FloatCmp
22
18
{
19
+ public const DECIMAL_SEPARATOR = '. ' ;
20
+
23
21
/**
24
22
* @param float $a
25
23
* @param float $b
@@ -57,14 +55,11 @@ private static function strval(
57
55
float $ value ,
58
56
int $ scale
59
57
): 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
+ ''
64
63
);
65
-
66
- /** @var string $result */
67
- $ result = sprintf ($ format , $ value );
68
- return substr ($ result , 0 , -1 );
69
64
}
70
65
}
You can’t perform that action at this time.
0 commit comments