Number formatting: PHP function number_format ()

PHP number_format



() . . , .

number_format()



PHP - , . :

string number_format(float $number)
      
      



$number



.

, , . . .

<?php
$number1 = 12345678.4321;
$result1 = number_format($number1); // 12,345,678

$number2 = 12345678.5678;
$result2 = number_format($number2); // 12,345,679
?>
      
      



.

, PHP number_format



() .

string number_format(float $number, int $decimals)
      
      



$decimals



- (integer), , . , .

, , .

<?php
$number1 = 12345678.4321;
$result1 = number_format($number1, 2); // 12,345,678.43

$number2 = 12345678.5678;
$result2 = number_format($number2, 1); // 12,345,679.6

$number3 = 12345678;
$result3 = number_format($number3, 3); // 12,345,679.000
?>
      
      



. .





PHP function number_format




, PHP number_format



() . , - .

string number_format(float $number, int $decimals, string $dec_point, string $thousands_sep)
      
      



$dec_point



, $thousands_sep



. , . , .

php number_format :

<?php
$number1 = 12345678.4321;
$number2 = 12345678.5678;
$number3 = 12345678;

$result1 = number_format($number1, 5, '.', ','); // 12,345,678.43210

$result2 = number_format($number2, 5, '^', ' '); // 12 345 678:56780

$result3 = number_format($number2, 5, '-', ''); // 12345678-56780

$result4 = number_format($number3, 5, '***', 'xxx'); // 12x345x678*000

?>
      
      



, .

Custom delimiters in the number_format PHP function




PHP number_format



() . , .




All Articles