From d8c4b5ecc436faa0ab25e4c4cf80bab977e22b4a Mon Sep 17 00:00:00 2001 From: Krzysztof Pyrkosz Date: Thu, 12 Dec 2019 06:00:38 +0100 Subject: [PATCH 1/2] Fix floating point type (#20) --- src/Format.php | 3 +++ src/field/NumericField.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Format.php b/src/Format.php index 8a0b1d5..141fe69 100644 --- a/src/Format.php +++ b/src/Format.php @@ -509,6 +509,9 @@ protected function createField($data) { $field = Field::create($data['t']); $field->setName(rtrim($data['n'])); $field->setLength($data['ll']); + if ($data['t'] == Field::TYPE_NUMERIC && isset($data['dd'])) { + $field->setDecimalCount(2); + } return $field; } diff --git a/src/field/NumericField.php b/src/field/NumericField.php index de679d3..ddde0d5 100644 --- a/src/field/NumericField.php +++ b/src/field/NumericField.php @@ -44,7 +44,7 @@ public function fromData($data) { if (!$this->getDecimalCount()) { return (integer)substr($data, 0, $this->getLength()); } else { - return (float)number_format(substr($data, 0, $this->getLength()), $this->getDecimalCount(), '.', ''); + return (float)number_format((float)substr($data, 0, $this->getLength()), $this->getDecimalCount(), '.', ''); } } From 023d8531c1fd0b4b88e6b3b50541666f63360d53 Mon Sep 17 00:00:00 2001 From: Krzysztof Pyrkosz Date: Mon, 12 Jul 2021 13:41:33 +0200 Subject: [PATCH 2/2] Fix decimal count in floating point type (#20) --- src/Format.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Format.php b/src/Format.php index 141fe69..f91e4d1 100644 --- a/src/Format.php +++ b/src/Format.php @@ -509,8 +509,8 @@ protected function createField($data) { $field = Field::create($data['t']); $field->setName(rtrim($data['n'])); $field->setLength($data['ll']); - if ($data['t'] == Field::TYPE_NUMERIC && isset($data['dd'])) { - $field->setDecimalCount(2); + if ($data['t'] === Field::TYPE_NUMERIC && isset($data['dd'])) { + $field->setDecimalCount($data['dd']); } return $field; }