SoFunction
Updated on 2025-03-02

PHP converts 1000 or 100 million units of numbers

php makes ten thousand numbers. The conversion of billions

/**
  * Format numbers
  */
public function float_number($number){
    $length = strlen($number);  //Number length    if($length > 8){ //Billion units        $str = substr_replace(strstr($number,substr($number,-7),' '),'.',-1,0)."100 million";
    }elseif($length >4){ //Ten thousand units        //The first two are intercepted        $str = substr_replace(strstr($number,substr($number,-3),' '),'.',-1,0)."Ten thousand";
    }else{
        return $number;
    }
    return $str;
}

Knowledge points expansion:

PHP number to capital amount (object-oriented version)

I have been searching online for a long time but haven't had a complete use, so I had to write it myself (the integer part of the effective digits reaches tens of trillions, and the decimal part reaches four decimal places)

$time_start=getmicrotime();

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());

return ((float)$usec + (float)$sec);

}

/// CLASS BEGIN //

class Num2cny

{
/** Caps */

private $cny_num = array('zero','one','two','Ginseng','Si','Wu','land','Qi','eight','Nine');

/** Units of integer parts*/

private $cny_int_unit = array('round','pickup','Bai','thousand','Ten thousand','pickup','Bai','thousand','100 million','pickup','Bai','thousand','Ten thousand','pickup','Bai','thousand');

/** Units of decimal parts*/

private $cny_dec_unit = array('horn','point','Li','hour');

/** Is it greater than 1*/

private $greater_than_1 = FALSE;

/**

 * Convert to capitalization amount.

 * @access public

 * @param string

 * @return string

 */

public function conversion($str) {
if(empty($str))
{
return 'Please input a numeric value!';
}
if( ! is_numeric($str))
{
return 'It is not a numeric value!';
}
$str = str_replace(',','',trim($str));// Filter out left and right spaces and commas$str = ltrim($str,'0');
$_integerStr = '';// Integer part number$_decimalStr = '';// Decimal number

This is the article about PHP converting 1000 or 100 million units into numbers. For more information about PHP converting 100000 units into numbers, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!