Конвертировать суммы, где ввод «100K», «100M» и т. Д.

В настоящее время я работаю над сайтом, где мне нужно конвертировать суммы с буквами за ним, например:

100M = 100.000.000 

Я создал способ сделать это по-другому, от:

 100.000.000 = 100M 

Вот моя текущая функция:

 function Convert($Input){ if($Input<=1000){ $AmountCode = "GP"; $Amount = $Input; } else if($Input>=1000000){ $AmountCode = "M"; $Amount = floatval($Input / 1000000); } else if($Input>=1000){ $AmountCode = "K"; $Amount = $Input / 1000; } $Array = array( 'Amount' => $Amount, 'Code' => $AmountCode ); $Result = json_encode($Array); return json_decode($Result); } 

Теперь мне нужно что-то, что может отфильтровать это:

 100GP = 100 100K = 100.000 100M = 100.000.000 

Я искал некоторые вещи, и я попытался с explode(); и другие функции, но он не работает, как я хочу.

Есть ли кто-нибудь, кто может мне помочь?

     <?php /** * @param string $input * @return integer */ function revert($input) { if (!is_string($input) || strlen(trim($input)) == 0) { throw new InvalidArgumentException('parameter input must be a string'); } $amountCode = array ('GP' => '', 'K' => '000', 'M' => '000000'); $keys = implode('|', array_keys($amountCode)); $pattern = '#[0-9]+(' . $keys .'){1,1}$#'; $matches = array(); if (preg_match($pattern, $input, $matches)) { return $matches[1]; } else { throw new Exception('can not revert this input: ' . $input); } }