转换价格类型为xxx milion xxx千[复制]

This question already has an answer here:

I have to write a function to change a pricetype from (ex: 25400000) to 25 milion 400 thousand . I have a code but it just change when the price type is even (ex : 25000000) . Here is my code .

static public function priceFormat($number, $type ='vnd')
{
    $subfix = 'vnd';
    if ($type == 'vnd'){
        $temp = substr($number, -6, -1);
        if ($temp == '000000'){
            $number = str_replace("000000", '', $number);
            $subfix = 'million';
        }
    }
    while (true) {
        $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
        if ($replaced != $number) {
            $number = $replaced;
        } else {
            break;
        }
    }
    if ($type != 'vnd')
        return $number.' '.$type;
    return $number.' '.$subfix;
}
</div>

This code:

$number = 25400055;

$millionsRemainder = $number % 1000000;

$millions = ($number - $millionsRemainder) / 1000000;

$thousandsRemainder = $millionsRemainder % 1000;

$thousands = ($millionsRemainder - $thousandsRemainder) / 1000;

echo $millions . ' million ' . $thousands . ' thousands ' . ' and ' . $thousandsRemainder;

Should output "25 million 400 thousands and 55"