try this:
class IS_DECIMAL:
def __init__(self,decimals=2,error_message="Invalid"):
self.decimals=decimals
self.error_message=error_message
def __call__(self,value):
try:
value=int(float(value)*(10**self.decimals))
return (value,None)
except:
return (value,self.error_message)
def format(self,value):
return float(value)/10**self.decimals
On Mar 20, 7:41 pm, Joe Barnhart <[email protected]> wrote:
> The easiest workaround is to use INTEGER and leave all amounts in
> cents, i.e. 123 instead of 1.23. If all math is done with the implied
> decimal point on integers, you will never have floating-point round-
> off errors. Only put in the decimal point when you are ready to
> display the value. (Massimo -- Maybe a validator can help here?)
>
> -- Joe B.
>
> On Mar 20, 12:03 pm, Paco <[email protected]> wrote:
>
> > I've been trying web2py for a couple of days and I believe is just
> > great. I'm so excited that I'm planning to build my own accounting and
> > invoicing application, which is, in the other hand, not so complex in
> > my case.
>
> > I need (and I believe many more people do) a DECIMAL field type or
> > maybe a CURRENCY type since there are many applications that need
> > fixed precision numbers.
>
> > It seems to me that is shouldn't be very difficult to do since most
> > databases, including SQLite, support NUMERIC or DECIMAL types.
>
> > It would be a great new feature. Are there any plans to do such a
> > thing? Or maybe there is a nice workaround to do this in web2py?
>
> > Cheers,
> > Paco
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---