Passed
Push — master ( c2eae6...17ee88 )
by Sébastien
02:33
created

NumberConversion   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 5
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A truncateFloat() 0 8 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 2
    public static function truncateFloat(float $number, int $decimals): float
17
    {
18 2
        $power = 10 ** $decimals;
19 2
        if ($number > 0) {
20 2
            return floor($number * $power) / $power;
21
        }
22
23 1
        return ceil($number * $power) / $power;
24
    }
25
}
26