ASSIGNJS Decimals

50 views
Skip to first unread message

villas

unread,
Aug 2, 2019, 10:31:34 AM8/2/19
to web2py-users
It would be great if ASSIGNJS would serialize Decimal numbers as Float rather then quoted Str.
Unless I'm overlooking something,  I suppose this would be a bug?
Thanks.

villas

unread,
Aug 5, 2019, 8:28:17 AM8/5/19
to web2py-users
Here is an example.  I think this is a problem:

>>> from gluon.serializers import json
>>> json(decimal.Decimal(123.456))
'"123.4560000000000030695446184836328029632568359375"'

I think this is what a user would intend:

>>> json(float(decimal.Decimal(123.456)))
'123.456'

Suggestion:

In gluon.serializers.py the function def custom_json(o) contains this:

    elif isinstance(o, decimal.Decimal):
        return str(o)

I suggest this would be better: return float(o)


Massimo Di Pierro

unread,
Aug 18, 2019, 1:47:23 AM8/18/19
to web2py-users
right. done. thanks.
Reply all
Reply to author
Forward
0 new messages