Number formatting

I have a table with numbers like this:

19809.1
1982.0
1982.19

Its currency. Is there a function that I can use to format these numbers?

19 809,10
1 982,00
1 982,19
+4
source share
5 answers

This is pretty easy with number_format:

echo number_format($number, 2, ",", " ");
+7
source

DOCUMENTATION

<?php

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>
+3
source

http://www.php.net/manual/es/function.number-format.php

// notación francesa
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
+1
0

number_format:

$val=array(19809.1, 1982.0, 1982.19);

foreach ($val as $v)
 echo number_format($v, 2, ',', ' ');
                     _  _   _    _
                     ^  ^   ^    ^
                value   |   |    |
        decimal positions   |    |
            decimal separator    |
               thousands separator

:

19 809,10
1 982,00
1 982,19
0

Source: https://habr.com/ru/post/1532859/


All Articles