= 0) { $afterPoint = str_pad($afterPoint, $precision + 1, '0', STR_PAD_RIGHT); if ($precision > 0) { $lastChar = substr($afterPoint, $precision - 1, 1); $afterPointNew = ''; $beforPointNew = ''; if ((int)substr($afterPoint, $precision, 1) >= 5) { $step = 0; while ($lastChar == 9) { if ($step < $precision) { $afterPointNew = '0' . $afterPointNew; $step++; if ($step <= $precision - 1) { $lastChar = (int)substr($afterPoint, $precision - $step - 1, 1); } else { $lastChar = (int)substr($beforPoint, $precision - $step - 1, 1); } } else { $beforPointNew = '0' . $beforPointNew; $step++; $lastChar = (int)substr($beforPoint, $precision - $step - 1, 1); } } $lastChar = (int)$lastChar + 1; if ($step < $precision) { $afterPointNew = substr($afterPoint, 0, $precision - $step - 1) . $lastChar . $afterPointNew; $beforPointNew = $beforPoint; } else { $beforPointNew = substr($beforPoint, 0, $precision - $step - 1) . $lastChar . $beforPointNew; } $roundedResult = $beforPointNew . '.' . $afterPointNew; } else { $afterPoint = substr($afterPoint, 0, $precision); $roundedResult = $beforPoint . '.' . str_pad($afterPoint, $precision, '0', STR_PAD_LEFT); } } else { $beforPoint = (int)$beforPoint + (((int)substr($afterPoint, $precision, 1) >= 5)?1:0); $roundedResult = $beforPoint; } } else { $beforPointLength = strlen($beforPoint); if ($beforPointLength <= abs($precision)) { $roundedResult = 0; } else { $lastChar = substr($beforPoint, $precision - 1, 1); if ((int)substr($beforPoint, $precision, 1) >= 5) { $step = 0; while ($lastChar == 9) { if ($step < $beforPointLength - abs($precision)) { $beforPointNew = '0' . $beforPointNew; $step++; $lastChar = (int)substr($beforPoint, $precision - $step - 1, 1); } } $lastChar = (int)$lastChar + 1; $beforPointNew = $lastChar . $beforPointNew; if ($beforPointLength > abs($precision) + $step + 1) { $symbolsCount = $beforPointLength - abs($precision) - $step - 1; $beforPointNew = substr($beforPoint, 0, $symbolsCount) . $beforPointNew; } else { $beforPointLength++; } $beforPointNew = str_pad($beforPointNew, $beforPointLength, '0', STR_PAD_RIGHT); $roundedResult = $beforPointNew; } else { $beforPoint = substr($beforPoint, 0, $precision); $roundedResult = str_pad($beforPoint, $beforPointLength, '0', STR_PAD_RIGHT); } } } $roundedResult = $sign . $roundedResult; return (float)$roundedResult; } public static function myBaseConvert($number, $alphabet) { $base = strlen($alphabet); $number = intval($number); if ($number != 0) { $result = ''; while ($number > 0) { $digit = $number % $base; $result = $alphabet[$digit] . $result; $number = (int)($number / $base); } } else { $result = $alphabet[0]; } return $result; } public static function myMakeAlphabet($alphabet) { $result = array(); $n = strlen($alphabet); for ($i = 0; $i < $n; ++$i) { if (!isset($result[$alphabet[$i]])) { $result[$alphabet[$i]] = $i; } } return $result; } public static function myBaseDeconvert($string, $alphabetArray) { if (!is_array($alphabetArray)) { //passed non-array, so try to make one $alphabetArray = Qs_Math::myMakeAlphabet($alphabetArray); } $base = count($alphabetArray); $n = strlen($string); $result = 0; for ($i = 0; $i < $n; ++$i) { $result *= $base; $result += $alphabetArray[$string[$i]]; } return $result; } public static function sizeToByteString($size) { $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); for ($i=0; $size >= 1024 && $i < 9; $i++) { $size /= 1024; } return round($size, 2) . ' ' . $sizes[$i]; } }