Changeset 15476 for main/waeup.kofa
- Timestamp:
- 27 Jun 2019, 06:07:52 (5 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r15446 r15476 4 4 1.6.1.dev0 (unreleased) 5 5 ======================= 6 7 * Use decimal.Decimal to counteract Python floating point limitation. 6 8 7 9 * Add level 0 (None) to course levels. -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_utils.py
r12110 r15476 123 123 utils.SYSTEM_MAX_LOAD['virt-mem'] = -(sys.maxint) # negative int 124 124 assert utils.expensive_actions_allowed() == False 125 126 def test_format_float(self): 127 format_float= KofaUtils().format_float 128 # This is the floating point problem ... 129 self.assertEqual(4.6*100, 459.99999999999994) 130 # ... which is solved in format_float 131 self.assertEqual(format_float(4.6 ,1), '4.6') 132 self.assertEqual(format_float(4.6 ,2), '4.60') 133 self.assertEqual(format_float(4.6 ,3), '4.600') 134 self.assertEqual(format_float(4.6 ,4), '4.6000') -
main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py
r15432 r15476 22 22 import string 23 23 import pytz 24 import decimal 24 25 from copy import deepcopy 25 26 from random import SystemRandom as r … … 417 418 418 419 def format_float(self, value, prec): 420 # >>> 4.6 * 100 421 # 459.99999999999994 422 value = decimal.Decimal(str(value)) 419 423 # cut floating point value 420 424 value = int(pow(10, prec)*value) / (1.0*pow(10, prec))
Note: See TracChangeset for help on using the changeset viewer.