Commit 49bb00554dee2455d288a68165fafdf16d7ce129
1 parent
207522e8
add round for koef margin grup before writing to bd
Showing
2 changed files
with
19 additions
and
1 deletions
Show diff stats
backend/controllers/RgGrupController.php
| ... | ... | @@ -168,7 +168,8 @@ class RgGrupController extends BaseController |
| 168 | 168 | |
| 169 | 169 | $row['importer_id'] = trim($importer_id); |
| 170 | 170 | $row['margin_id'] = ltrim($key, '!'); |
| 171 | - $row['koef'] = \Yii::$app->converter->convertTo('float', $value); | |
| 171 | + $row['koef'] = \Yii::$app->converter->convertTo('float', $value, ['precision' => 6]); | |
| 172 | + | |
| 172 | 173 | |
| 173 | 174 | $arr_values[] = $row; |
| 174 | 175 | ... | ... |
common/components/parsers/CustomConverter.php
| ... | ... | @@ -15,6 +15,8 @@ class CustomConverter extends Converter |
| 15 | 15 | public static $importer_id; |
| 16 | 16 | public static $brand; |
| 17 | 17 | public static $begin_of_the_day = true; |
| 18 | + // точность для округления десятичных чисел | |
| 19 | + public static $precision = 2; | |
| 18 | 20 | |
| 19 | 21 | public static function convertToDetails(array $row) |
| 20 | 22 | { |
| ... | ... | @@ -145,5 +147,20 @@ class CustomConverter extends Converter |
| 145 | 147 | return $res; |
| 146 | 148 | } |
| 147 | 149 | |
| 150 | + public static function convertToFloat( $value ) | |
| 151 | + { | |
| 152 | + if ($value == '') { | |
| 153 | + $value = 0; | |
| 154 | + } | |
| 155 | + $value = trim(str_replace(",", ".", $value)); | |
| 156 | + $value = preg_replace("/[^0-9.]+/", "", strtoupper($value)); | |
| 157 | + | |
| 158 | + if ($value == '') { | |
| 159 | + return ''; | |
| 160 | + } | |
| 161 | + $value = round( (float)$value, self::$precision ); | |
| 162 | + | |
| 163 | + return $value; | |
| 164 | + } | |
| 148 | 165 | |
| 149 | 166 | } |
| 150 | 167 | \ No newline at end of file | ... | ... |