1 <?php
2
3 4 5 6 7
8
9 namespace Ublaboo\DataGrid\Column;
10
11 use Ublaboo\DataGrid\Row;
12
13 class ColumnNumber extends Column
14 {
15 16 17
18 protected $align = 'right';
19
20 21 22
23 protected $number_format = [
24 0,
25 '.',
26 ' '
27 ];
28
29
30 31 32 33 34
35 public function getColumnValue(Row $row)
36 {
37 $value = parent::getColumnValue($row);
38
39 if (!is_numeric($value)) {
40 return $value;
41 }
42
43 return number_format(
44 $value,
45 $this->number_format[0],
46 $this->number_format[1],
47 $this->number_format[2]
48 );
49 }
50
51
52 53 54 55 56 57
58 public function setFormat($decimals = 0, $dec_point = '.', $thousands_sep = ' ')
59 {
60 $this->number_format = [$decimals, $dec_point, $thousands_sep];
61
62 return $this;
63 }
64
65
66 67 68
69 public function getFormat()
70 {
71 return [
72 $this->number_format[0],
73 $this->number_format[1],
74 $this->number_format[2]
75 ];
76 }
77
78 }
79