Passed
Pull Request — master (#480)
by Def
02:04
created

NumericHelper::normalizeFloat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Helper;
6
7
final class NumericHelper
8
{
9
    /**
10
     * Returns string representation of a number value without thousands separators and with dot as decimal separator.
11
     *
12
     * @param float|string $value
13
     *
14
     * @return string
15
     */
16
    public static function normalizeFloat(float|string $value): string
17
    {
18
        if (is_float($value)) {
19
            $value = (string)$value;
20
        }
21
22
        $value = str_replace([' ', ','], ['', '.'], $value);
23
        return preg_replace('/\.(?=.*\.)/', '', $value);
24
    }
25
}
26