From 49bb00554dee2455d288a68165fafdf16d7ce129 Mon Sep 17 00:00:00 2001 From: Mihail Date: Wed, 18 Nov 2015 15:48:43 +0200 Subject: [PATCH] add round for koef margin grup before writing to bd --- backend/controllers/RgGrupController.php | 3 ++- common/components/parsers/CustomConverter.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/controllers/RgGrupController.php b/backend/controllers/RgGrupController.php index eb09621..42e2b52 100755 --- a/backend/controllers/RgGrupController.php +++ b/backend/controllers/RgGrupController.php @@ -168,7 +168,8 @@ class RgGrupController extends BaseController $row['importer_id'] = trim($importer_id); $row['margin_id'] = ltrim($key, '!'); - $row['koef'] = \Yii::$app->converter->convertTo('float', $value); + $row['koef'] = \Yii::$app->converter->convertTo('float', $value, ['precision' => 6]); + $arr_values[] = $row; diff --git a/common/components/parsers/CustomConverter.php b/common/components/parsers/CustomConverter.php index 30a1495..dc967d2 100755 --- a/common/components/parsers/CustomConverter.php +++ b/common/components/parsers/CustomConverter.php @@ -15,6 +15,8 @@ class CustomConverter extends Converter public static $importer_id; public static $brand; public static $begin_of_the_day = true; + // точность для округления десятичных чисел + public static $precision = 2; public static function convertToDetails(array $row) { @@ -145,5 +147,20 @@ class CustomConverter extends Converter return $res; } + public static function convertToFloat( $value ) + { + if ($value == '') { + $value = 0; + } + $value = trim(str_replace(",", ".", $value)); + $value = preg_replace("/[^0-9.]+/", "", strtoupper($value)); + + if ($value == '') { + return ''; + } + $value = round( (float)$value, self::$precision ); + + return $value; + } } \ No newline at end of file -- libgit2 0.21.4