From 89d3f69a1bf5d386498a3009c5d0b35b4d433eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 24 Mar 2009 15:53:16 +0100 Subject: [PATCH] Fix digits tests for float entries It now uses string value instead of float to avoid float imprecision --- tryton/common/cellrendererfloat.py | 15 +++++++++++---- .../gui/window/view_form/view/form_gtk/float.py | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/tryton/common/cellrendererfloat.py b/tryton/common/cellrendererfloat.py index def4cb9c57..5042f947f2 100644 --- a/tryton/common/cellrendererfloat.py +++ b/tryton/common/cellrendererfloat.py @@ -19,12 +19,19 @@ class CellRendererFloat(CellRendererInteger): if new_value == '-': return - if len(str(int(locale.atof(new_value)))) > self.digits[0]: + locale.atof(new_value) + + decimal_point = locale.localeconv()['decimal_point'] + + new_int = new_value + new_decimal = '' + if decimal_point in new_value: + new_int, new_decimal = new_value.rsplit(decimal_point, 1) + + if len(new_int) > self.digits[0] \ + or len(new_decimal) > self.digits[1]: entry.stop_emission('insert-text') - exp_value = locale.atof(new_value) * (10 ** self.digits[1]) - if exp_value - int(exp_value) != 0.0: - entry.stop_emission('insert-text') except: entry.stop_emission('insert-text') diff --git a/tryton/gui/window/view_form/view/form_gtk/float.py b/tryton/gui/window/view_form/view/form_gtk/float.py index ed0970be00..992e3b4b47 100644 --- a/tryton/gui/window/view_form/view/form_gtk/float.py +++ b/tryton/gui/window/view_form/view/form_gtk/float.py @@ -44,11 +44,18 @@ class Float(Integer): else: digits = self.digits - if len(str(int(locale.atof(new_value)))) > digits[0]: + locale.atof(new_value) + + decimal_point = locale.localeconv()['decimal_point'] + + new_int = new_value + new_decimal = '' + if decimal_point in new_value: + new_int, new_decimal = new_value.rsplit(decimal_point, 1) + + if len(new_int) > digits[0] \ + or len(new_decimal) > digits[1]: entry.stop_emission('insert-text') - exp_value = locale.atof(new_value) * (10 ** digits[1]) - if exp_value - int(exp_value) != 0.0: - entry.stop_emission('insert-text') except: entry.stop_emission('insert-text')