Encodes the number as a PHP number representation.
@param float $float The number to encode
@param array $options The float encoding options
@param callable $encode Callback used to encode values
@return string The PHP code representation for the number
504985
private function encodeNumber($float, array $options, callable $encode)
    {
        if ($this->isInteger($float, $options['float.integers'])) {
            return $this->encodeInteger($float, $encode);
        } elseif ($float === 0.0) {
            return '0.0';
        } elseif ($options['float.export']) {
            return var_export((float) $float, true);
        }

        return $this->encodeFloat($float, $this->determinePrecision($options));
    }
821517
private function encodeNumber($num)
    {
        $encodeString = '';

        while ($num >= 0x20) {
            $nextValue = (0x20 | ($num & 0x1f)) + 63;
            $encodeString .= chr($nextValue);
            $num >>= 5;
        }
        $finalValue = $num + 63;
        $encodeString .= chr($finalValue);
        return $encodeString;
    }
781873
protected function json_encode_options($options)
    {
        $data = $this->prepare_options($options);

        $json = json_encode($data['options']);

        $json = str_replace($data['toReplace'], $data['original'], $json);

        return $json;
    }
1346938
public static function encodeJson($value, int $options = JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION): string
    {
        return \json_encode($value, $options);
    }
187401
def float_encode(self, value):
    
    if value < 128:
      code = value
    elif value > 31743:
      code = 255
    else:
      exp=0
      value>>=3
      while(value>31):
        exp+=1
        value>>=1
      exp<<=4
      code = 0x80 | exp | (value & 0x0F)
    return code
1169267
protected function encode($data, $options = 0)
    {
        // Check is already json string.
        if (is_string($data) && strlen($data) >= 1) {
            $firstChar = $data[0];

            if (in_array($firstChar, ['[', '{', '"'])) {
                return $data;
            }
        }

        // Clear json_last_error()
        json_encode(null);

        $json = json_encode($data, $options);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \UnexpectedValueException(sprintf('JSON encode failure: %s', json_last_error_msg()));
        }

        return $json;
    }
445906
protected function encodeValues(&$values)
    {
        if (is_array($values)) {
            foreach ($values as &$value) {
                $value = $this->encodeValues($value);
            }
        } elseif (is_float($values)) {
            $values = Common::forceDotAsSeparatorForDecimalPoint($values);
        } elseif (is_string($values)) {
            $values = htmlentities($values, ENT_COMPAT, 'UTF-8');
            $values = str_replace('$', '&#36;', $values);
        }
        return $values;
    }
1069782
public static function number(float $n, int $precision = 0): string
    {
        return self::$locale->number(round($n, $precision));
    }
228701
public static function encode($value)
    {
        $value = gmp_init($value, 10);
        $octets = chr(gmp_strval(gmp_and($value, 0x7f), 10));

        $rightShift = function ($number, $positions) {
            return gmp_div($number, gmp_pow(2, $positions));
        };

        $value = $rightShift($value, 7);
        while (gmp_cmp($value, 0) > 0) {
            $octets .= chr(gmp_strval(gmp_or(0x80, gmp_and($value, 0x7f)), 10));
            $value = $rightShift($value, 7);
        }

        return strrev($octets);
    }
1134844
public function encodeDecimal($integer, $options)
    {
        if ($integer === 1 << (\PHP_INT_SIZE * 8 - 1)) {
            return sprintf('(int)%s%d', $options['whitespace'] ? ' ' : '', $integer);
        }

        return var_export($integer, true);
    }
485598
public function encode(Message $message, int $options = 0): string
    {
        $ctx = new Context($options);
        $qdCount = $anCount = $nsCount = $arCount = 0;

        foreach ($message->getQuestionRecords() as $record) {
            if (!$this->encodeQuestionRecord($ctx, $record)) {
                goto done;
            }

            $qdCount++;
        }

        foreach ($message->getAnswerRecords() as $record) {
            if (!$this->encodeResourceRecord($ctx, $record)) {
                goto done;
            }

            $anCount++;
        }

        foreach ($message->getAuthorityRecords() as $record) {
            if (!$this->encodeResourceRecord($ctx, $record)) {
                goto done;
            }

            $nsCount++;
        }

        foreach ($message->getAdditionalRecords() as $record) {
            if (!$this->encodeResourceRecord($ctx, $record)) {
                goto done;
            }

            $arCount++;
        }

        done:
        $packet = $this->encodeHeader($ctx, $message, $qdCount, $anCount, $nsCount, $arCount) . $ctx->data;

        if (!($options & EncodingOptions::FORMAT_TCP)) {
            \assert(
                \strlen($packet) <= 512,
                new \Error('UDP packet exceeds 512 byte limit: got ' . \strlen($packet) . ' bytes')
            );

            return $packet;
        }

        \assert(
            \strlen($packet) <= 65535,
            new \Error('TCP packet exceeds 65535 byte limit: got ' . \strlen($packet) . ' bytes')
        );

        return \pack('n', \strlen($packet)) . $packet;
    }
28809
public static function encode(array $dataToSerialize, $options = 0) {
		$result = json_encode($dataToSerialize, $options);

		$error = null;
		if (json_last_error() !== JSON_ERROR_NONE) {
			$error = 'JSON encoding failed: ' . json_last_error_msg();
		}

		if ($result === false || $error) {
			throw new RuntimeException($error ?: 'JSON encoding failed');
		}

		return $result;
	}
801681
public static function encode($value, $options = JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK)
    {
        if ($value instanceof \Traversable)
        {
            $value = \iterator_to_array($value);
        }

        return \json_encode($value, $options);
    }
692676
public function toWords($p_num, $p_locale = '', $p_options = array())
    {
        if (empty($p_locale) && isset($this) && $this instanceof Number) {
            $p_locale = $this->locale;
        }
        if (empty($p_locale)) {
            $p_locale = 'en_US';
        }
        $classname = self::loadLocale($p_locale, '_toWords');
        $obj       = new $classname;
        if (!is_int($p_num)) {
            $p_num = $obj->normalizeNumber($p_num);
            $p_num = preg_replace('/(.*?)('.preg_quote($obj->decimalPoint).'.*?)?$/', '$1', $p_num);
        }
        if (empty($p_options)) {
            return trim($obj->toWords($p_num));
        }

        return trim($obj->toWords($p_num, $p_options));
    }
1275242
public function encode($data, $options = 0) {
        $json = null;

        if ($data instanceof IArrayable) {
            $json = @json_encode($data->toArray(), $options);
        } else if ($data instanceof IJsonable) {
            $json = $data->toJson($options);
        } else if (is_array($data) || is_object($data)) {
            $json =  @json_encode($data, $options);
        } else {
            throw new InvalidDataTypeException(
                s('Can not convert data of type "%s" to json.', get_type($data))
            );
        }

        if ($json === false) {
            throw new JsonEncodeException(json_last_error_msg(), $data);
        }

        return $json;
    }
198359
private function formatFloat($float, $digits)
    {
        $digits = max((int) $digits, 1);
        $string = rtrim(number_format($float, $digits, '.', ''), '0');

        return substr($string, -1) === '.' ? $string . '0' : $string;
    }
928227
public static function encode(
        $value,
        $options = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION
    ) {
        $json = \json_encode($value, $options);
        if (JSON_ERROR_NONE !== ($error = \json_last_error())) {
            throw new JsonException(\json_last_error_msg(), $error);
        }

        return $json;
    }