Notice: Undefined offset: 8192 in /www/k/a/u8542/public_html/classes/errors.php on line 121

Notice: Undefined offset: 8192 in /www/k/a/u8542/public_html/classes/errors.php on line 157

Notice: Undefined offset: 8192 in /www/k/a/u8542/public_html/classes/errors.php on line 121

Notice: Undefined offset: 8192 in /www/k/a/u8542/public_html/classes/errors.php on line 157
PHP - number_format

number_format

 

PHP -> Funkcie -> Funkcie pre prácu s reťazcami PHP -> number_format

Syntax


string number_format ( float number [, int decimals [, string dec_point, string thousands_sep] ] )

Popis


Príkaz jazyka PHP
Format a number with grouped thousands

number_format() returns a formatted version of number. This function accepts either one, two or four parameters (not three):

If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.

If two parameters are given, number will be formatted with decimals decimals with a dot (".") in front, and a comma (",") between every group of thousands.

If all four parameters are given, number will be formatted with decimals decimals, dec_point instead of a dot (".") before the decimals and thousands_sep instead of a comma (",") between every group of thousands.

Only the first character of thousands_sep is used. For example, if you use foo as thousands_sep on the number 1000, number_format() will return 1f000.

Príklad


<?php

$number = 1234.56;

// bez desatinnej časti a tisíce oddelené čiarkou
$english_format_number = number_format($number);
// 1,234

// desatinná čiarka, tisíce oddelené medzerou, zaokrúhlené na 2 desatiny
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// desatinná bodka, zaokrúhlené na 2 desatiny
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>


Pozri aj


sprintf, printfsscanf.



vytlačiť článok  hľadať súvisiace články 

Chat ku článku

Vyhľadávanie na stránke
Reklama
Náhodný obrázok
náhodný obrázok
Kontakty

Martin Kasman, M Software
Smreková 3095/23
Email: martin@kasman.sk

Telefón: 0908 270 294