转换输入为“100K”、“100M”等的金额

Convert amounts where input is "100K", "100M" etc

我目前在一个网站上工作,我需要用后面的字母转换金额,例如:

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);
    }
}