Fix digits tests for float entries

It now uses string value instead of float to avoid float imprecision
This commit is contained in:
Cédric Krier committed 2009-03-24 15:53:16 +01:00
1 parent 768711ad94
commit 89d3f69a1b
2 files changed
+22 -8

No files matched your search

+11 -4
View File
@@ -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')
@@ -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')