| Conditions | 3 |
| Paths | 3 |
| Total Lines | 14 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 17 | public static function smartRound(float $number, int $idealLength = 3): float |
||
| 18 | { |
||
| 19 | if ($number == 0) { |
||
| 20 | return 0.0; |
||
| 21 | } |
||
| 22 | |||
| 23 | $intPart = intval($number); |
||
| 24 | |||
| 25 | $precision = $idealLength - mb_strlen((string) $intPart); |
||
| 26 | if ($precision < 0) { |
||
| 27 | $precision = 0; |
||
| 28 | } |
||
| 29 | |||
| 30 | return (float) sprintf("%.{$precision}f", $number); |
||
| 31 | } |
||
| 33 |