PHP sayı_format() İşlevi
Örnek
Numaraları biçimlendir:
<?php
echo number_format("1000000")."<br>";
echo number_format("1000000",2)."<br>";
echo number_format("1000000",2,",",".");
?>
Tanım ve Kullanım
number_format() işlevi, bir sayıyı gruplandırılmış binlerle biçimlendirir.
Not: Bu işlev bir, iki veya dört parametreyi destekler (üç değil).
Sözdizimi
number_format(number,decimals,decimalpoint,separator)
Parametre Değerleri
Parameter | Description |
---|---|
number | Required. The number to be formatted. If no other parameters are set, the number will be formatted without decimals and with comma (,) as the thousands separator. |
decimals | Optional. Specifies how many decimals. If this parameter is set, the number will be formatted with a dot (.) as decimal point |
decimalpoint | Optional. Specifies what string to use for decimal point |
separator | Optional. Specifies what string to use for thousands separator. Only the first character of separator is used. For example, "xxx" will give the same output as "x" Note: If this parameter is given, all other parameters are required as well |
Teknik detaylar
Geri dönüş değeri: | Biçimlendirilmiş sayıyı döndürür |
---|---|
PHP Sürümü: | 4+ |
Değişiklik günlüğü: | PHP 5.4'ten itibaren, bu işlev decimalpoint ve separator parametrelerinde birden çok baytı destekler . Eski sürümlerde her ayırıcının yalnızca ilk baytı kullanıldı. |
Daha fazla örnek
Örnek
Bir fiyat döndürmek istiyorsunuz: Bir parametre sayıyı yuvarlar (ondalık olmadan biçimlendirilir). İki parametre istediğiniz sonucu vermelidir:
<?php
$num = 1999.9;
$formattedNum = number_format($num)."<br>";
echo $formattedNum;
$formattedNum = number_format($num, 2);
echo $formattedNum;
?>
❮ PHP Dize Referansı