Php show the number of money-friendly version

June 28, 2019 16:35:10

This method is better scalability

/*
     * Right amount converted into digital visual representation of Chinese characters easy to read
     */

    function amountConversion(float $amount = 0) {
        $moneyArray = [
            ['length' => 100000000, 'unit' => '亿'],
            ['length' => 10000, 'unit' => '万'],
            ['length' => 1, 'unit' => '元']
        ];

        $return = '';
        foreach ($moneyArray as $k => $v) {
            if ($amount > $v['length']) {
                $temp = intval($amount / $v['length']);
                $return .= $temp . $v['unit'];
                $amount -= $temp * $v['length'];
            }
        }
        return $return;
    }

 

Guess you like

Origin www.cnblogs.com/zx-admin/p/11103490.html