to chinese number
@param $num
@param bool $mode
@return mixed|string
483144
static public function toChineseNum($num, $mode = true)
    {
        $char = array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九");
        $dw = array("", "十", "百", "千", "", "万", "亿", "兆");
        $dec = "点";
        $retval = "";

        if ($mode)
            preg_match_all("/^0*(\d*)\.?(\d*)/", $num, $ar);
        else
            preg_match_all("/(\d*)\.?(\d*)/", $num, $ar);
        if ($ar[2][0] != "")
            $retval = $dec . ch_num($ar[2][0], false); //如果有小数，先递归处理小数
        if ($ar[1][0] != "") {
            $str = strrev($ar[1][0]);
            for ($i = 0; $i < strlen($str); $i++) {
                $out[$i] = $char[$str[$i]];
                if ($mode) {
                    $out[$i] .= $str[$i] != "0" ? $dw[$i % 4] : "";
                    if ($str[$i] + ($str[$i - 1] ?? 0) == 0)
                        $out[$i] = "";
                    if ($i % 4 == 0)
                        $out[$i] .= $dw[4 + floor($i / 4)];
                }
            }
            $retval = join("", array_reverse($out)) . $retval;
        }

        if (strpos($retval, "一十") === 0) {
            $retval = str_replace("一十", "十", $retval);
        }

        return $retval;
    }
394400
public function GetFinallyKeywords( $num = 10 )
     {
         $n = 0;
         $arr = $this->GetFinallyIndex();
         $okstr = '';
         foreach( $arr as $k => $v )
         {
            //排除长度为1的词
            if( strlen($k)==1 ) {
                continue;
            }
            //排除长度为2的非英文词
            elseif( strlen($k)==2 && preg_match('/[^0-9a-zA-Z]/', $k) ) {
                continue;
            
            }
            //排除单个中文字
            elseif( strlen($k) < 4 && !preg_match('/[a-zA-Z]/', $k)) {
                continue;
            }
            $okstr .= ($okstr=='' ? $k : ','.$k);
            $n++;
            if( $n > $num ) break;
         }
         return $okstr;
     }
799404
protected function toWords($num = 0)
    {
        $ret = [];

        $ret_minus = '';

        // check if $num is a valid non-zero number
        if (!$num || preg_match('/^-?0+$/', $num) || !preg_match('/^-?\d+$/', $num)) {
            return $this->zero;
        }

        // add a minus sign
        if (substr($num, 0, 1) == '-') {
            $ret_minus = $this->minus . $this->wordSeparator;

            $num = substr($num, 1);
        }

        // strip excessive zero signs
        $num = ltrim($num, '0');

        // split $num to groups of three-digit numbers
        $num_groups = $this->splitNumber($num);

        $sizeof_numgroups = count($num_groups);

        // go through the groups in reverse order, so that the last group could be determined
        for ($i = $sizeof_numgroups - 1, $j = 1; $i >= 0; $i--, $j++) {
            if (!isset($ret[$j])) {
                $ret[$j] = '';
            }

            // what is the corresponding exponent for the current group
            $pow = $sizeof_numgroups - $i;

            // skip processment for empty groups
            if ($num_groups[$i] != '000') {
                if ($num_groups[$i] > 1) {
                    if ($pow == 1) {
                        $ret[$j] .= $this->showDigitsGroup(
                            $num_groups[$i],
                            0,
                            !$this->lastAnd && $i
                        ) . $this->wordSeparator;
                        $ret[$j] .= self::$exponent[($pow - 1) * 3];
                    } elseif ($pow == 2) {
                        $ret[$j] .= $this->showDigitsGroup(
                            $num_groups[$i],
                            -1,
                            !$this->lastAnd && $i
                        ) . $this->wordSeparator;
                        $ret[$j] .= self::$miscStrings['hiliadi'] . $this->wordSeparator;
                    } else {
                        $ret[$j] .= $this->showDigitsGroup(
                            $num_groups[$i],
                            1,
                            !$this->lastAnd && $i
                        ) . $this->wordSeparator;
                        $ret[$j] .= self::$exponent[($pow - 1) * 3] . $this->pluralSuffix . $this->wordSeparator;
                    }
                } else {
                    if ($pow == 1) {
                        $ret[$j] .= $this->showDigitsGroup(
                            $num_groups[$i],
                            0,
                            !$this->lastAnd && $i
                        ) . $this->wordSeparator;
                    } elseif ($pow == 2) {
                        $ret[$j] .= self::$exponent[($pow - 1) * 3] . $this->wordSeparator;
                    } else {
                        $ret[$j] .= self::$digits[1][1] . $this->wordSeparator . self::$exponent[($pow - 1) * 3] . $this->wordSeparator;
                    }
                }
            }
        }

        return $ret_minus . rtrim(implode('', array_reverse($ret)), $this->wordSeparator);
    }
350557
public function set($num, $v1, $v2, $v3, $v4 = null, $v5 = 10, $replace = false)
    {
        if (!$this->is_stat) {
            return false;
        }

        $num = (int)$num;
        $v1  = trim($v1);
        $v2  = trim($v2);
        $v3  = trim($v3);
        $v4  = trim($v4);
        if ($num <= 0 || !isset($v1[0]) || !isset($v2[0]) || !isset($v3[0])) {
            return false;
        }

        //采样
        if ($v4 !== null) {
            $prob = ceil(100 / $v5);
            $rt   = mt_rand(1, $prob);
            $v4   = $rt == 1 ? substr($v4, 0, 500) : null;
        }

        $data = array(
            //按照DB划分
            'dbf'     => $this->db_prefix,
            //累计值
            'num'     => (int)$num,
            //大分类
            'v1'      => $v1,
            //小分类
            'v2'      => $v2,
            //具体统计对象
            'v3'      => $v3,
            //采样信息
            'v4'      => $v4,
            'replace' => $replace,
            //记录时间
            'time'    => time(),
        );
        array_push($this->data, $data);

        if (count($this->data) >= 100) {
            $this->log();
            $this->data = array();
        }
    }
48326
function internalNumber( $number )
    {
        if ( preg_match( '/^(['.$this->PositiveSymbol.']|['.$this->NegativeSymbol.'])?([0-9]*|[0-9]{1,3}(['.$this->ThousandsSeparator.'][0-9]{3,3})*)(['.$this->DecimalSymbol.'][0-9]+)?$/', trim( $number ) ) )
        {
            $number = str_replace( ' ', '', $number );
            if ( $this->PositiveSymbol )
                $number = str_replace( $this->PositiveSymbol, '', $number );
            $number = str_replace( $this->NegativeSymbol, '-', $number );
            $number = str_replace( $this->ThousandsSeparator, '', $number );
            $number = str_replace( $this->DecimalSymbol, '.', $number );
        }
        return $number;
    }
856669
static function numberOnly($string, $decimalPoint = ".", $convertedDecimalPoint = ".") {
		$vystup="";
		for ($i=0;$i<strlen($string);$i++) {
			$znak=substr($string,$i,1);
			if (is_numeric($znak)) $vystup.=$znak;
			else {
				if ($znak==$decimalPoint) {
					$vystup.=$convertedDecimalPoint;
				}
			}
		}
		return $vystup;
	}
739338
function run($num=1)
    {
        //初始化事件系统
        if (!($this->protocol instanceof Swoole\Server\UDP_Server_Protocol))
        {
            return error(902);
        }
        //建立服务器端Socket
        $this->server_sock = $this->create("udp://{$this->host}:{$this->port}");
        stream_set_blocking($this->server_sock,$this->server_block);
        $this->server_socket_id = (int)$this->server_sock;
        //设置事件监听，监听到服务器端socket可读，则有连接请求
        $this->protocol->onStart();
        $this->server_loop();
    }
939428
public function D2B($num)
    {
        $this->preOpMethodParamsCheck(array($num));

        /* Make sure that we're dealing with a decimal number. */
        $num = $this->decodeHex($num);

        try {

            $bin = '';

            while ($this->math->comp($num, '0') > 0) {
                switch ($this->math->mod($num, '2')) {
                    case '1':
                        $bin .= '1';
                        break;
                    default:
                        $bin .= '0';
                        break;
                }

                $num = $this->math->div($num, '2');
            }

            return $bin;

        } catch (\Exception $e) {
            throw $e;
        }
    }
148779
protected function convert($num)
    {
        if ($num instanceof NumericTypeInterface) {
            return $num;
        }
        if (is_numeric($num)) {
            return $this->calcEngine->convertNumeric($num);
        }

        $type = (is_object($num) ? get_class($num) : gettype($num));
        throw new \BadMethodCallException('No solution for unknown type: ' . $type);
    }
594596
public function number2Chinese($simple = true)
    {
        $str = '';
        $unitPos = 0;

        while ($this->num > 0) {
            //分段字符串
            $sectionStr = '';

            //取最低四位
            $section = $this->getLowBitPart($this->num, 4);

            //获取段中文字符串
            $this->section2Chinese($section, $sectionStr);

            //拼接段数字单位
            $sectionStr .= ($section != 0) ? self::CHINESE_UNIT_SECTION[$unitPos] : self::CHINESE_UNIT_SECTION[0];

            $this->num = intval($this->num / 10000);
            ++$unitPos;

            //补零
            if (($section < 1000) && ($section > 0) && $this->num > 0) {
                $sectionStr = self::CHINESE_NUM_CHAR[0] . $sectionStr;
            }

            $str = $sectionStr . $str;
        }

        return $str;
    }
1203993
public function translate($string, &$num) {
        if ($this->short_circuit)
            return $string;
        $this->load_tables();

        if ($this->enable_cache) {
            // Caching enabled, get translated string from cache
            if (array_key_exists($string, $this->cache_translations))
                return $this->cache_translations[$string];
            else
                return $string;
        }
        else {
            // Caching not enabled, try to find string
            $num = $this->find_string($string);
            if ($num == -1)
                return $string;
            else
                return $this->get_translation_string($num);
        }
    }
274530
public function shorten($num) {
		$str = '';

		while ($num > 0) {
			$str = $this->alphabet[($num % $this->base)] . $str;
			$num = (int) ($num / $this->base);
		}

		return $str;
	}
452238
private static function numberFormatStandardized($num_format)
    {
        if ($num_format == 'money') {
            $num_format = 'dollar';
        }
        if ($num_format == 'number') {
            $num_format = 'integer';
        }

        if ($num_format == 'string') {
            $num_format = '@';
        } else {
            if ($num_format == 'integer') {
                $num_format = '0';
            } else {
                if ($num_format == 'date') {
                    $num_format = 'YYYY-MM-DD';
                } else {
                    if ($num_format == 'datetime') {
                        $num_format = 'YYYY-MM-DD HH:MM:SS';
                    } else {
                        if ($num_format == 'price') {
                            $num_format = '#,##0.00';
                        } else {
                            if ($num_format == 'dollar') {
                                $num_format = '[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00';
                            } else {
                                if ($num_format == 'euro') {
                                    $num_format = '#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]';
                                }
                            }
                        }
                    }
                }
            }
        }
        $ignore_until = '';
        $escaped = '';
        for ($i = 0, $ix = strlen($num_format); $i < $ix; $i++) {
            $c = $num_format[$i];
            if ($ignore_until == '' && $c == '[') {
                $ignore_until = ']';
            } else {
                if ($ignore_until == '' && $c == '"') {
                    $ignore_until = '"';
                } else {
                    if ($ignore_until == $c) {
                        $ignore_until = '';
                    }
                }
            }
            if ($ignore_until == '' && ($c == ' ' || $c == '-' || $c == '(' || $c == ')') && ($i == 0 || $num_format[$i - 1] != '_')) {
                $escaped .= "\\" . $c;
            } else {
                $escaped .= $c;
            }
        }
        return $escaped;
    }
229355
function _convertNumber($num)
    {
        // Integer in the range 0..2**16-1
        if ((preg_match("/^\d+$/", $num)) and ($num <= 65535)) {
            return pack("Cv", $this->ptg['ptgInt'], $num);
        } else { // A float
            if ($this->_byte_order) { // if it's Big Endian
                $num = strrev($num);
            }
            return pack("Cd", $this->ptg['ptgNum'], $num);
        }
    }
767693
private function ord_unicode($num)
    {
        if ($num <= 0x7F) {
            return chr($num);
        }
        if ($num <= 0x7FF) {
            return chr(($num >> 6) + 192).chr(($num & 63) + 128);
        }
        if ($num <= 0xFFFF) {
            return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
        }
        if ($num <= 0x1FFFFF) {
            return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
        }

        return '';
    }
331237
public static function getVd(int $num)
    {
        $i = 2;
        $sum = 0;

        foreach (array_reverse(str_split($num)) as $v) {
            if ($i === 8) $i = 2;
            $sum += $v * $i;
            ++$i;
        }

        $dig = 11 - ($sum % 11);

        if ($dig === 11) $dig = 0;
        if ($dig === 10) $dig = 'K';

        return $dig;
    }
130194
public function random($num = 1)
	{
		if($this->isSelectBefore)
		{
			$this->__selectBefore();
		}
		$opt = $this->getOption();
		$this->setOption($opt);
		$result = $this->field(array('count(*)'=>'count','max(' . $this->pk . ')'=>'max','min(' . $this->pk . ')'=>'min'))->getOne();
		$this->setOption($opt);
		$max_count=$result['max']-$result['count']+$num;
		// 随机出记录位置
		$limits = randomNums($result['min'], $result['max'], $max_count);
		$this->where(array($this->pk=>array('in',$limits)));
		$this->limit($num);
		$results = $this->orderByField($this->pk,$limits)->select();
		$this->__selectAfter($results,$opt);
		return $results;
	}