static function correctAmount($amount, $round = true) { if (strpos($amount, '.') === 0) { $amount = '0' . $amount; } elseif (strpos($amount, '.') === false) { if (strpos($amount, ',') !== false) { $amount = str_replace(',', '.', $amount); } else { $amount = $amount . '.00'; } } else { $amount = str_replace(',', '', $amount); } if ($round) { $amount = (string) AECToolbox::roundAmount($amount); } else { $amount = (string) $amount; } // You wouldn't believe me if I told you. Localization is a dark place. if (strpos($amount, ',') !== false) { $amount = str_replace(',', '.', $amount); } $a = explode('.', $amount); if (empty($a[1])) { $amount = $a[0] . '.00'; } else { if ($round) { $amount = $a[0] . '.' . substr(str_pad($a[1], 2, '0'), 0, 2); } else { $amount = $a[0] . '.' . str_pad($a[1], 2, '0'); } } return $amount; }