Fascinating. As an experiment I replaced str with repr and it usually works with float. Float is better then integer because allows migrations from one decimal type to float and vice versa and allows for expressions involving different field types without major errors.
The problem is that when it fails, it has major failures. Everybody should be aware that there will be much bigger rounding errors with type='decimal' on sqlite than with type='double'. With double the rounding errors will be of the order of required decimal precision, much bigger than double precision. That is because is >>> a = 0.3/3 # is float >>> print str(a)[0:5] 0.1 while >>> from decimal import Decimal >>> b=Decimal(repr(a)[0:5]) >>> print b 0.099 Conversions like the one above are necessary step to get data in/out of database. The more I look into this the more I think we should not support it if the database does not support it. Massimo On Nov 13, 9:27 pm, Jonathan Lundell <jlund...@pobox.com> wrote: > On Nov 13, 2009, at 4:36 PM, Massimo Di Pierro wrote: > > > In theory double has 53 bits. Yet I tried and it does not seem to work > > properly. It rounds to the cents. You may want to try the attached > > files. Perhaps I am doing something wrong. > > I'm not advocating floating point; I think it's a pain, and if integer is > working, that's better. But.... > > >>> from decimal import * > >>> b = Decimal("1234567891.987654321") > >>> b > > Decimal('1234567891.987654321')>>> float(b) > 1234567891.9876542 > >>> str(float(b)) > '1234567891.99' > >>> repr(float(b)) > > '1234567891.9876542' > > I haven't checked, but it looks like an artifact of float.str. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---