Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Calculator.php

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\Internal

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal