Ignore:
Timestamp:
27 Jun 2019, 06:07:52 (5 years ago)
Author:
Henrik Bettermann
Message:

Use decimal.Decimal to counteract Python floating point limitation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_utils.py

    r12110 r15476  
    123123        utils.SYSTEM_MAX_LOAD['virt-mem'] = -(sys.maxint)  # negative int
    124124        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')
Note: See TracChangeset for help on using the changeset viewer.