From 763eaf83da7272e147c157c41e1a6c7ba1567b6a Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 8 Sep 2023 12:20:52 +1000 Subject: [PATCH] Fix #3733. Fix round function precision error. --- src/ifcopenshell-python/ifcopenshell/util/selector.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index 502fe8333b..b568e6b476 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -25,6 +25,7 @@ import ifcopenshell.util.element import ifcopenshell.util.placement import ifcopenshell.util.geolocation import ifcopenshell.util.classification +from decimal import Decimal filter_elements_grammar = lark.Lark( @@ -188,9 +189,9 @@ class FormatTransformer(lark.Transformer): return str(args[0])[int(args[1]) : int(args[2])] def round(self, args): - value = args[0] or 0.0 - nearest = float(args[1]) - result = round(float(value) / nearest) * nearest + value = Decimal(args[0] or 0.0) + nearest = Decimal(args[1]) + result = round(value / nearest) * nearest if nearest % 1 == 0: return str(int(result)) return str(result)