Passed
Push — master ( 864fd9...c2eae6 )
by Sébastien
03:26
created

NumberConversion::truncateFloat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2019 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Common\Math;
13
14
final class NumberConversion
15
{
16
    private function __construct()
17
    {
18
    }
19
20 2
    public static function truncateFloat(float $number, int $decimals): float
21
    {
22 2
        $power = 10 ** $decimals;
23 2
        if ($number > 0) {
24 2
            return floor($number * $power) / $power;
25
        }
26
27 1
        return ceil($number * $power) / $power;
28
    }
29
}
30