| 98 | } |
| 99 | |
| 100 | private function normalizeNumberString(string $str): string { |
| 101 | $str = trim($str); |
| 102 | $hasComma = str_contains($str, ','); |
| 103 | $hasDot = str_contains($str, '.'); |
| 104 | |
| 105 | if ($hasComma && $hasDot) { |
| 106 | if (strrpos($str, ',') > strrpos($str, '.')) { |
| 107 | // comma as decimal separator |
| 108 | $str = str_replace('.', '', $str); |
| 109 | $str = str_replace(',', '.', $str); |
| 110 | } else { |
| 111 | // dot as decimal separator |
| 112 | $str = str_replace(',', '', $str); |
| 113 | } |
| 114 | } elseif ($hasComma) { |
| 115 | $idx = strrpos($str, ','); |
| 116 | $digits = strlen($str) - $idx - 1; |
| 117 | if ($digits <= 2) { |
| 118 | $str = str_replace(',', '.', $str); |
| 119 | } else { |
| 120 | $str = str_replace(',', '', $str); |
| 121 | } |
| 122 | } elseif ($hasDot) { |
| 123 | $idx = strrpos($str, '.'); |
| 124 | $digits = strlen($str) - $idx - 1; |
| 125 | if ($digits > 2) { |
| 126 | $str = str_replace('.', '', $str); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return str_replace(' ', '', $str); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Compare two values and return comparison result similar to spaceship operator |