Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
floatfield.php
1<?php
10
12
20{
22 protected $precision;
23
25 protected $scale;
26
35 public function __construct($name, $parameters = array())
36 {
37 parent::__construct($name, $parameters);
38
39 if(isset($parameters['scale']))
40 {
41 $this->scale = intval($parameters['scale']);
42 }
43
44 if(isset($parameters['precision']))
45 {
46 $this->precision = intval($parameters['precision']);
47 }
48 }
49
56 {
57 $this->precision = (int) $precision;
58 return $this;
59 }
60
66 public function configureScale($scale)
67 {
68 $this->scale = (int) $scale;
69 return $this;
70 }
71
75 public function getPrecision()
76 {
77 return $this->precision;
78 }
79
83 public function getScale()
84 {
85 return $this->scale;
86 }
87
93 public function cast($value)
94 {
95 if ($this->is_nullable && $value === null)
96 {
97 return $value;
98 }
99
100 if ($value instanceof SqlExpression)
101 {
102 return $value;
103 }
104
105 $value = doubleval($value);
106
107 if ($this->scale !== null)
108 {
109 $value = round($value, $this->scale);
110 }
111
112 return $value;
113 }
114
121 public function convertValueFromDb($value)
122 {
123 return $this->getConnection()->getSqlHelper()->convertFromDbFloat($value);
124 }
125
132 public function convertValueToDb($value)
133 {
134 if ($value instanceof SqlExpression)
135 {
136 return $value;
137 }
138
139 return $value === null && $this->is_nullable
140 ? $value
141 : $this->getConnection()->getSqlHelper()->convertToDbFloat($value);
142 }
143
147 public function getGetterTypeHint()
148 {
149 return $this->getNullableTypeHint('\\float');
150 }
151
155 public function getSetterTypeHint()
156 {
157 return $this->getNullableTypeHint('\\float');
158 }
159}
__construct($name, $parameters=array())