[egenix-users] DateTime error rounding seconds

M.-A. Lemburg mal at lemburg.com
Tue Apr 2 20:31:36 CEST 2002


Edwin Grubbs wrote:
> 
> I am having a problem with DateTime incorrectly rounding the floating
> point second value down 1/100 of second.
> 
> Python 2.2 (#1, Mar 13 2002, 12:34:11)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from mx.DateTime import *
> >>> DateTime(2002, 1, 2, 3, 4, 5.00)
> <DateTime object for '2002-01-02 03:04:05.00' at 8126658>
> >>> DateTime(2002, 1, 2, 3, 4, 5.01)
> <DateTime object for '2002-01-02 03:04:05.00' at 8152098>
> >>> DateTime(2002, 1, 2, 3, 4, 5.02)
> <DateTime object for '2002-01-02 03:04:05.01' at 8126658>
> >>> DateTime(2002, 1, 2, 3, 4, 5.03)
> <DateTime object for '2002-01-02 03:04:05.03' at 8152098>
> >>> DateTime(2002, 1, 2, 3, 4, 5.04)
> <DateTime object for '2002-01-02 03:04:05.04' at 8126658>
> >>> DateTime(2002, 1, 2, 3, 4, 5.05)
> <DateTime object for '2002-01-02 03:04:05.04' at 8152098>
> >>> DateTime(2002, 1, 2, 3, 4, 5.06)
> <DateTime object for '2002-01-02 03:04:05.05' at 8126658>

That's because 5.05 is really 5.0499999999999998. mxDateTime's
repr() function truncates the seconds value to avoid accidental
cases of a 60 reading when you really only have 59.6 seconds.

Use now().second to access the true seconds value with
full accuracy.

HTH, 
-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/



More information about the egenix-users mailing list