function Calculator::toBase
Converts a number to an arbitrary base.
This method can be overridden by the concrete implementation if the underlying library has built-in support for base conversion.
Parameters
string $number The number to convert, following the Calculator conventions.:
int $base The base to convert to, validated from 2 to 36.:
Return value
string The converted number, lowercase.
1 method overrides Calculator::toBase()
- GmpCalculator::toBase in vendor/
brick/ math/ src/ Internal/ Calculator/ GmpCalculator.php - Converts a number to an arbitrary base.
File
-
vendor/
brick/ math/ src/ Internal/ Calculator.php, line 336
Class
- Calculator
- Performs basic operations on arbitrary size integers.
Namespace
Brick\Math\InternalCode
public function toBase(string $number, int $base) : string {
$negative = $number[0] === '-';
if ($negative) {
$number = \substr($number, 1);
}
$number = $this->toArbitraryBase($number, self::ALPHABET, $base);
if ($negative) {
return '-' . $number;
}
return $number;
}