将数字转为 K/M/G 为单位的简写

@param integer $iNum
@static
@access public
@return string
494724
public static function convertNumToDigitalUnit($iNum) {
		foreach (['', 'K', 'M', 'G', 'T', 'P', 'G', 'E', 'Z'] as $sUnit) {
			if ((int)round($iNum) < 1000) {
				break;
			}
			$iNum = $iNum / 1024;
		}
		return ($iNum < 10 ? sprintf('%.01f', $iNum) : (int)round($iNum))
			. ($sUnit ? ' ' . $sUnit : '');
	}
743254
public static function word(int $num): string
    {
        $numberWordMap = [
            1 => Yii::t('yuncms', 'One'),
            2 => Yii::t('yuncms', 'Two'),
            3 => Yii::t('yuncms', 'Three'),
            4 => Yii::t('yuncms', 'Four'),
            5 => Yii::t('yuncms', 'Five'),
            6 => Yii::t('yuncms', 'Six'),
            7 => Yii::t('yuncms', 'Seven'),
            8 => Yii::t('yuncms', 'Eight'),
            9 => Yii::t('yuncms', 'Nine')
        ];

        if (isset($numberWordMap[$num])) {
            return $numberWordMap[$num];
        }

        return (string)$num;
    }
334673
private static function getUploadMaxFileSizeInBytes() {
    $val = trim(ini_get('upload_max_filesize'));
    $unit = strtolower(substr($val, -1));
    switch ($unit) {
      case 'g':
        $val *= 1024;
        // Fall through
      case 'm':
        $val *= 1024;
        // Fall through
      case 'k':
        $val *= 1024;
        break;
    }
    return intval($val);
  }
1076332
public static function GetSize($bytes) {
		if ($bytes >= 1073741824) {
			$bytes = number_format($bytes/1073741824, 2).' GB';
		} elseif ($bytes >= 1048576) {
			$bytes = number_format($bytes/1048576, 2).' MB';
		} elseif ($bytes >= 1024) {
			$bytes = number_format($bytes/1024, 2).' KB';
		} elseif ($bytes > 1) {
			$bytes = $bytes.' bytes';
		} elseif ($bytes == 1) {
			$bytes = $bytes.' byte';
		} else {
			$bytes = '0 bytes';
		}
		return $bytes;
	}
1089076
public function decode($in)
    {
        $ord = array(
            '~' => ord('~'),
            'z' => ord('z'),
            'u' => ord('u'),
            '!' => ord('!')
        );

        $out = '';
        $state = 0;
        $chn = null;

        $l = strlen($in);

        for ($k = 0; $k < $l; ++$k) {
            $ch = ord($in[$k]) & 0xff;

            if ($ch == $ord['~']) {
                break;
            }
            if (preg_match('/^\s$/',chr($ch))) {
                continue;
            }
            if ($ch == $ord['z'] && $state == 0) {
                $out .= chr(0) . chr(0) . chr(0) . chr(0);
                continue;
            }
            if ($ch < $ord['!'] || $ch > $ord['u']) {
                throw new Exception('Illegal character in ASCII85Decode.');
            }

            $chn[$state++] = $ch - $ord['!'];

            if ($state == 5) {
                $state = 0;
                $r = 0;
                for ($j = 0; $j < 5; ++$j)
                    $r = $r * 85 + $chn[$j];
                $out .= chr($r >> 24);
                $out .= chr($r >> 16);
                $out .= chr($r >> 8);
                $out .= chr($r);
            }
        }
        $r = 0;

        if ($state == 1) {
            throw new Exception('Illegal length in ASCII85Decode.');
        }

        if ($state == 2) {
            $r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
            $out .= chr($r >> 24);

        } else if ($state == 3) {
            $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85  + ($chn[2]+1) * 85 * 85;
            $out .= chr($r >> 24);
            $out .= chr($r >> 16);

        } else if ($state == 4) {
            $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85  + $chn[2] * 85 * 85  + ($chn[3]+1) * 85 ;
            $out .= chr($r >> 24);
            $out .= chr($r >> 16);
            $out .= chr($r >> 8);
        }

        return $out;
    }
979882
public static function makeMsgId()
    {
        static $sequence = 0;
        static $t = 0;
        if (!$t) {
            $t = static::getMillisecond();
            $t = ($t - $t % 1000) / 1000;
            $t = $t % 10000 * 10000;
        }
        //获取msgId
        ++$sequence;

        return $t + $sequence;
    }
898738
public static function getBytesFromSizeMeasurement($measurement) {
		$bytes = doubleval($measurement);
		if (stripos($measurement, 'G')) {
			$bytes *= 1024 * 1024 * 1024;
		} elseif (stripos($measurement, 'M')) {
			$bytes *= 1024 * 1024;
		} elseif (stripos($measurement, 'K')) {
			$bytes *= 1024;
		}
		return $bytes;
	}
570585
public static function getBytes($value){

		$value = trim($value);
		$unit = $value{strlen($value)-1};

		$value = floatval($value);

		switch(strtolower($unit)){

			case 'g':

				$multiplier = 1073741824;

			break;

			case 'm':

				$multiplier = 1048576;

			break;

			case 'k':

				$multiplier = 1024;

			break;

			default:

				ExceptionHandler::notice('Number::getBytes() expects unit to be either "g", "m" or "k"');
				$multiplier = 1;
		}

		return $multiplier * $value;
	}
899540
private function formatDuration(float $duration): string {
        if ($duration < 1.0e-3) {
            $n = number_format($duration * 1.0e6, 0);
            $sx = 'μs';
        } elseif ($duration < 1) {
            $n = number_format($duration * 1000, 0);
            $sx = 'ms';
        } elseif ($duration < 60) {
            $n = number_format($duration, 1);
            $sx = 's';
        } elseif ($duration < 3600) {
            $n = number_format($duration / 60, 1);
            $sx = 'm';
        } elseif ($duration < 86400) {
            $n = number_format($duration / 3600, 1);
            $sx = 'h';
        } else {
            $n = number_format($duration / 86400, 1);
            $sx = 'd';
        }

        $result = rtrim($n, '0.').$sx;
        return $result;
    }
1147989
public static function form ($in = '', $data = []) {
		if (isset($in['insert']) || isset($data['insert'])) {
			return static::__callStatic_internal(__FUNCTION__, func_get_args());
		}
		if ($in === false) {
			return '';
		}
		if (is_array($in)) {
			return static::__callStatic_internal(__FUNCTION__, [$in, $data]);
		}
		if (isset($in['method'])) {
			$data['method'] = $in['method'];
		}
		if (!isset($data['method'])) {
			$data['method'] = 'post';
		}
		if (strtolower($data['method']) == 'post') {
			if (!is_array($in)) {
				$in .= static::form_csrf();
			} else {
				$in['in'] .= static::form_csrf();
			}
		}
		return static::wrap($in, $data, __FUNCTION__);
	}
568398
public static function GetPhpIniSizeLimit ($iniVarName) {
		$rawIniValue = @ini_get($iniVarName);
		if ($rawIniValue === FALSE) {
			return 0;
		} else if ($rawIniValue === NULL) {
			return NULL;
		}
		$unit = strtoupper(substr($rawIniValue, -1));
		$multiplier = (
			$unit == 'M' 
				? 1048576 
				: ($unit == 'K' 
					? 1024 
					: ($unit == 'G' 
						? 1073741824 
						: 1)));
		return intval($multiplier * floatval($rawIniValue));
	}
1206842
protected function getIniBytes($iniName = '', $val = '')
    {
        if ($iniName !== '') {
            $val = ini_get($iniName);
            if ($val === false) {
                return 0;
            }
        }
        $val = trim($val, "bB \t\n\r\0\x0B");
        $last = strtolower($val[strlen($val) - 1]);
        $val = (int)$val;
        switch ($last) {
            case 't':
                $val *= 1024;
            case 'g':
                $val *= 1024;
            case 'm':
                $val *= 1024;
            case 'k':
                $val *= 1024;
        }
        return $val;
    }
1243809
public function invertm($num, $mod)
    {
        $num = $this->input($num);
        $mod = $this->input($mod);

        $x = '1';
        $y = '0';
        $num1 = $mod;

        do {
            $tmp = bcmod($num, $num1);

            $q = bcdiv($num, $num1);

            $num = $num1;

            $num1 = $tmp;

            $tmp = bcsub($x, bcmul($y, $q));

            $x = $y;

            $y = $tmp;

        } while (bccomp($num1, '0'));

        if (bccomp($x, '0') < 0) {
            $x = bcadd($x, $mod);
        }

        if (substr($num, 0, 1) === '-') {
            $x = bcsub($mod, $x);
        }

        return $x;
    }
1209101
static function getLocaleDateFormat($in_format)
    {

        $out_format = $in_format;
        if ($in_format == "%d/%m/%Y") {
            $out_format = "d-m-Y";
        }

        if ($in_format == "%Y/%m/%d") {
            $out_format = "Y-m-d";
        }

        if ($in_format == "%m/%Y/%d") {
            $out_format = "m-Y-d";
        }

        if ($in_format == "%d-%m-%Y") {
            $out_format = "d-m-Y";
        }

        if ($in_format == "%Y-%m-%d") {
            $out_format = "Y-m-d";
        }

        if ($in_format == "%m-%Y-%d") {
            $out_format = "m-Y-d";
        }

        if (!$in_format) {
            $in_format = "d-m-Y";
        }

        return ($out_format);
    }
396909
public function getMacKey()
    {
        $key = $this->config['key'];

        $hexStrKey = substr($key, 0, 38);
        $hexFinal = "" . substr($key, 38, 2) . "00";

        $cca0 = ord($hexFinal);

        if ($cca0 > 70 && $cca0 < 97) {
            $hexStrKey .= chr($cca0 - 23) . substr($hexFinal, 1, 1);
        } else {
            if (substr($hexFinal, 1, 1) == "M") {
                $hexStrKey .= substr($hexFinal, 0, 1) . "0";
            } else {
                $hexStrKey .= substr($hexFinal, 0, 2);
            }
        }

        return pack("H*", $hexStrKey);
    }
239285
public function formatDateValue($in_tag, $in_value, $in_label)
    {

        $text = "";

        if (!$in_value) {
            return $text;
        }

        $in_label = ReporticoLocale::getLocaleDateFormat($in_label);

        $dy_tag = $in_tag . "_DAY";
        $mn_tag = $in_tag . "_MONTH";
        $yr_tag = $in_tag . "_YEAR";

        $tag = "";
        $tag .= '<input  type="hidden" name="HIDDEN_' . $in_tag . '"';
        $tag .= ' size="' . ($this->column_length) . '"';
        $tag .= ' maxlength="' . $this->column_length . '"';
        $tag .= ' value="' . $in_value . '">';
        $text .= $tag;

        if (AJAX_ENABLED) {
            $tag = "";

            if (preg_match("/TODATE/", $in_tag)) {
                $tag .= "";
            }

            $tag .= '<input  class="' . $this->lookup_query->getBootstrapStyle('textfield') . 'reportico-date-field" id="reportico-date-field_' . $in_tag . '" style="z-index: 1000" type="text" name="MANUAL_' . $in_tag . '"';
            $tag .= ' size="20"';
            $tag .= ' maxlength="20"';
            $tag .= ' value="' . $in_value . '">';
            $text .= $tag;
            return $text;
        }

        $dy = "FIXTHIS";
        $mn = "FIXTHIS";
        $yr = "FIXTHIS";
        switch ($this->criteria_display) {
            case "YMDFIELD":
            case "MDYFIELD":
            case "DMYFIELD":
            case "DMYFORM":

                $dyinput = '<SELECT name="' . $dy_tag . '">';
                for ($ct = 1; $ct <= 31; $ct++) {
                    $checked = "";
                    if ($ct == (int) $dy) {
                        $checked = "selected";
                    }

                    $dyinput .= '<OPTION ' . $checked . ' label="' . $ct . '" value="' . $ct . '">' . $ct . '</OPTION>';
                }
                $dyinput .= '</SELECT>';

                $mtinput = '<SELECT name="' . $mn_tag . '">';
                $cal = array(ReporticoLang::translate('January'), ReporticoLang::translate('February'), ReporticoLang::translate('March'), ReporticoLang::translate('April'), ReporticoLang::translate('May'), ReporticoLang::translate('June'),
                    ReporticoLang::translate('July'), ReporticoLang::translate('August'), ReporticoLang::translate('September'), ReporticoLang::translate('October'), ReporticoLang::translate('November'), ReporticoLang::translate('December'));
                for ($ct = 0; $ct <= 11; $ct++) {
                    $checked = "";
                    if ($ct == $mn - 1) {
                        $checked = "selected";
                    }

                    $mtinput .= '<OPTION ' . $checked . ' label="' . $cal[$ct] . '" value="' . $ct . '">' . $cal[$ct] . '</OPTION>';
                }
                $mtinput .= '</SELECT>';

                $yrinput = '<SELECT name="' . $yr_tag . '">';
                for ($ct = 2000; $ct <= 2020; $ct++) {
                    $checked = "";
                    if ($ct == $yr) {
                        $checked = "selected";
                    }

                    $yrinput .= '<OPTION ' . $checked . ' label="' . $ct . '" value="' . $ct . '">' . $ct . '</OPTION>';
                }
                $yrinput .= '</SELECT>';

                switch ($this->criteria_display) {
                case "YMDFIELD":
                        $text .= $yrinput . $mtinput . $dyinput;
                        break;

                case "MDYFIELD":
                        $text .= $mtinput . $dyinput . $yrinput;
                        break;

                case "DMYFIELD":
                case "DMYFORM":
                default:
                        $text .= $dyinput . $mtinput . $yrinput;
                        break;
                }

                break;

            default:
                $tag = "";

                if (preg_match("/TODATE/", $in_tag)) {
                    $tag .= "";
                }

                $tag .= '<input  type="text" name="MANUAL_' . $in_tag . '"';
                $tag .= ' size="20"';
                //$tag .= ' maxlength="'.$this->column_length.'"';
                $tag .= ' maxlength="20"';
                $tag .= ' value="' . $in_value . '">';
                $text .= $tag;

        }
        return $text;

    }
493329
public static function distance($distance_in_m) : string {
		if (self::$options['format_uom'] == 'METRIC') {
			return round($distance_in_m / 1000, 2) . i18n(null, 'km');
		} else {
			return round($distance_in_m / 1.60934 / 1000, 2) . i18n(null, 'mi');
		}
	}