PHP 8.1.28 Released!

NumberFormatter::format

numfmt_format

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

NumberFormatter::format -- numfmt_formatBir sayıyı biçemler

Açıklama

Nesne yönelimli kullanım

public NumberFormatter::format(int|float $sayı, int $tür = NumberFormatter::TYPE_DEFAULT): string|false

Yordamsal kullanım

numfmt_format(NumberFormatter $biçemleyici, int|float $sayı, int $tür = NumberFormatter::TYPE_DEFAULT): string|false

Bir sayıyı biçemleyici kurallarına uygun olarak biçemler.

Bağımsız Değişkenler

biçemleyici

NumberFormatter nesnesi.

sayı

Biçemlenecek sayı. int veya float türünde olabilir, diğer türler bir sayısal türe dönüştürülür.

tür

Kullanılacak biçemleme türü. NumberFormatter::TYPE_CURRENCY sabitinin desteklenmediği unutulmamalı, yerine NumberFormatter::formatCurrency() kullanılmalıdır.

Dönen Değerler

Bir hata oluşursa false, aksi takdirde biçemlenmiş değeri içeren dizge döner.

Örnekler

Örnek 1 - numfmt_format() örneği

<?php
$fmt
= numfmt_create( 'tr_TR', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
if(
intl_is_failure(numfmt_format($fmt))) {
report_error("Biçemleyici hatası");
}
?>

Örnek 2 - Nesne yönelimli kullanım örneği

<?php
$fmt
= new NumberFormatter( 'tr_TR', NumberFormatter::DECIMAL );
$fmt->format(1234567.891234567890000);
if(
intl_is_failure($fmt->getErrorCode())) {
report_error("Biçemleyici hatası");
}
?>

Yukarıdaki örneğin çıktısı:

1.234.567,891

Notlar

Bilginize:

Bu biçimlendirme yöntemiyle elde edilebilen biçimler, temel ICU kütüphanesinin, para birimini dar para birimi simgesiyle biçimlendirmek gibi, olanaklarını tam olarak kullanamaz.

Tüm olanaklar için msgfmt_format_message() kullanılabilir.

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
2
mrSplendid
1 year ago
on Linux you may need to install icu-data-full package for NumberFormatter to work properly with non-english locales.
To Top