From 5abedfb447e96186c8f0d2e34a955a2f799721b6 Mon Sep 17 00:00:00 2001 From: Jan Kapusta Date: Sun, 15 Aug 2021 12:17:17 +0200 Subject: [PATCH] fix floating point field and formatting --- 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..f91e4d1 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($data['dd']); + } 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(), '.', ''); } }