Tuesday, May 29, 2018

Re: money field question

On 29/05/2018 6:06 AM, Simon McConnell wrote:
> Work with what you've got (that being procrastination):
> http://www.structuredprocrastination.com
>

You should see the pile of stuff I'm avoiding. It's worth a PhD in
procrastination

>> poswald/python-money does the same and looks interesting. Might go there
>> and see how it works. It also has form and field helpers.

Although it has all the currencies and includes the correct number of
decimals in its CURRENCY dict it ignores them in calculations. You can
calculate with lengthy decimal tails and round it all at the end.

Which might be quite reasonable. The alternative is to round everything
to the correct number of decimals for the nominated currency before a
calculation. Might speak to an accountant or banker on that. I suspect
bankers round it at every step and catch the shavings in their hats.

Also, despite using decimal.Decimal under the covers it wants its money
as strings.

Python 3.6.3
>>> from money import money
>>> print(money.Money(23.45, 'AUD'))
AUD 23.449999999999999289457264239899814128875732421875
>>> print(money.Money('23.45', 'AUD'))
AUD 23.45
>>> money.CURRENCY['AUD'].decimals
2
>>> money.CURRENCY['AUD'].symbol
'$'
>>> money.CURRENCY['AUD'].name
'Australian Dollar'
>>>

Still thinking about this.

Mike






--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/198a5479-aae9-51a1-386f-d3258a0a2630%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment