Format a phone number. A phone number can support multiple variations,
depending on how many numbers are present.

@param int $value
@param string $format
@return string
358174
public static function phone($value, $format) {
        $value = preg_replace('/[^0-9]+/', '', $value);

        if (is_array($format)) {
            $length = mb_strlen($value);

            if ($length >= 11) {
                $format = $format[11];
            } else if ($length >= 10) {
                $format = $format[10];
            } else {
                $format = $format[7];
            }
        }

        return static::format($value, $format);
    }
882344
protected function formatValue($value)
    {
        $formatted_value = '<unknown parameter type>';

        if (is_object($value)) {
            $formatted_value = '<' . get_class($value) . ' object>';
        } elseif ($value === null) {
            $formatted_value = '<null>';
        } elseif (is_string($value)) {
            if (SwatString::validateUtf8($value)) {
                $formatted_value = "'" . $value . "'";
            } else {
                $formatted_value = '"' . SwatString::escapeBinary($value) . '"';
            }
        } elseif (is_int($value) || is_float($value)) {
            $formatted_value = strval($value);
        } elseif (is_bool($value)) {
            $formatted_value = $value ? 'true' : 'false';
        } elseif (is_resource($value)) {
            $formatted_value = '<resource>';
        } elseif (is_array($value)) {
            // check whether or not array is associative
            $keys = array_keys($value);
            $associative = false;
            $count = 0;
            foreach ($keys as $key) {
                if ($key !== $count) {
                    $associative = true;
                    break;
                }
                $count++;
            }

            $formatted_value = 'array(';

            $count = 0;
            foreach ($value as $key => $the_value) {
                if ($count > 0) {
                    $formatted_value .= ', ';
                }

                if ($associative) {
                    $formatted_value .= $this->formatValue($key);
                    $formatted_value .= ' => ';
                }
                $formatted_value .= $this->formatValue($the_value);
                $count++;
            }
            $formatted_value .= ')';
        }

        return $formatted_value;
    }
647292
public static function format($number, $format=Formatter::PHONE_E164) {
        $formattedNumber = '';
        $regex = "/[^0-9]/";
        $number = preg_replace($regex, "", $number);

        if(strlen($number) > 13)
            throw new \Exception('Unsupported Format for number '.$number);

        if(strlen($number) >10)
            $countryCode = "";
        else
            $countryCode = "91";
        $formattedNumber = "+$countryCode$number";
        return $formattedNumber;
    }
48425
protected function formatValue($format, $value)
    {
        switch ($format) {
            case Format::DATE:
                if ($value instanceof \DateTime) {
                    return $value->format('Y-m-d');
                }
                break;

            case Format::DATETIME:
                if ($value instanceof \DateTime) {
                    return $value->format('Y-m-d H:i:s');
                }
                break;

            case Format::FLOAT2:
                return sprintf("%.2f", $value);

            case Format::INTEGER:
                return sprintf("%d", $value);

            case Format::PCT:
                return $this->formatValue(Format::INTEGER, $value)." %";

            case Format::PCT2:
                return $this->formatValue(Format::FLOAT2, $value)." %";

            case Format::MONEY:
                return $this->formatValue(Format::INTEGER, $value)." €";

            case Format::MONEY2:
                return $this->formatValue(Format::FLOAT2, $value)." €";
        }

        return $value;
    }
30087
public static function format($phone, $format = PhoneNumberFormat::E164, $region = 'RU')
    {
        return self::phoneUtil()->format(self::phoneUtil()->parse($phone, $region), $format);
    }
774244
public static function formatSiret($value): string
    {
        $value = (string) (int) $value;
        if (!self::isSiret($value)) {
            return '';
        }
        return preg_replace('/^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{5})$/', '$1 $2 $3 $4', $value);
    }
1123505
public static function format($value)
    {
        $value = Utils::toString($value);
        $bn = Utils::toBn($value);
        $int = (int) $bn->toString();

        return $int;
    }
785375
public function formatCurrency($value, $currency, $precision=2)
    {
        $newValue = trim($value, " \0\x0B$currency");
        if (!is_numeric($newValue)) {
            return $value;
        }

        $pattern = $this->getPattern($value, 'Intl_NumberFormatCurrency');

        if ($newValue == round($newValue)) {
            // if no fraction digits available, don't show any
            $value = $this->formatNumberWithPattern($pattern, $newValue, 0, 0);
        } else {
            // show given count of fraction digits otherwise
            $value = $this->formatNumberWithPattern($pattern, $newValue, $precision, $precision);
        }

        return str_replace('¤', $currency, $value);
    }
394175
public static function format($value)
    {
        $value = (string) $value;
        $arguments = func_get_args();
        $digit = 64;

        if (isset($arguments[1]) && is_numeric($arguments[1])) {
            $digit = intval($arguments[1]);
        }
        $bn = Utils::toBn($value);
        $bnHex = $bn->toHex(true);
        $padded = mb_substr($bnHex, 0, 1);

        if ($padded !== 'f') {
            $padded = '0';
        }        
        return implode('', array_fill(0, $digit-mb_strlen($bnHex), $padded)) . $bnHex;
    }
799946
private static function formatValue($value)
    {
        // The `$value` argument could be a number (example: 123) or a numeric
        // string (example: '123'). A numeric string is recommended for
        // 32-bit systems to prevent unexpected truncation.
        //
        // To use a numeric string in a WHERE condition, it needs to be
        // wrapped in a pair of quotes.
        // For example:
        //     SELECT Id WHERE Id = '9223372036854775807'
        if (is_numeric($value) && !is_string($value)) {
            return $value;
        }

        return sprintf('\'%s\'', addslashes($value));
    }
652736
public function format($value): string
    {
        $value = $value->rate();

        if ($value instanceof PercentageDiscount) {
            return (new PercentFormatter($value))->format($value);
        }

        if ($value instanceof ValueDiscount) {
            return (new MoneyFormatter())->format($value);
        }
    }
875341
public static function formatToDecimal($value, $decimals = 2)
    {
        if (trim($value) != null) {
            return number_format($value, $decimals, '.', '');
        }
        return null;
    }
469793
public function Format($format)
    {
        if (!$this->value) {
            return null;
        }
        $formatter = $this->getFormatter();
        $formatter->setPattern($format);
        return $formatter->format($this->getTimestamp());
    }
589839
public function format($value, $maximumFractionDigits=0, $minimumFractionDigits=0)
    {
        if (is_string($value)
            && trim($value, '%') != $value
        ) {
            return $this->formatPercent($value, $maximumFractionDigits, $minimumFractionDigits);
        }

        return $this->formatNumber($value, $maximumFractionDigits, $minimumFractionDigits);
    }
1111294
public static function TEXTFORMAT($value, $format)
    {
        $value  = PHPExcel_Calculation_Functions::flattenSingleValue($value);
        $format = PHPExcel_Calculation_Functions::flattenSingleValue($format);

        if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) {
            $value = PHPExcel_Calculation_DateTime::DATEVALUE($value);
        }

        return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format);
    }
704278
public function asDate($value, $format = null)
    {
        if ($format == parent::FORMAT_WIDTH_SHORT) {
            $formatter = new IntlDateFormatter(Yii::$app->language, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
            $format = preg_replace(':(^|[^y])y{2,2}([^y]|$):', '$1yyyy$2', $formatter->getPattern());
        }

        return parent::asDate($value, $format);
    }
743180
public function format($format, $value)
    {
        switch ($format) {
            case 'date-time':
                return $this->formatDateTime($value);
            case 'date-time-http':
                return $this->formatDateTimeHttp($value);
            case 'date':
                return $this->formatDate($value);
            case 'time':
                return $this->formatTime($value);
            case 'timestamp':
                return $this->formatTimestamp($value);
            case 'boolean-string':
                return $this->formatBooleanAsString($value);
            default:
                return $value;
        }
    }