On 29/05/2018 10:10 PM, Melvyn Sopacua wrote:
>
> On dinsdag 29 mei 2018 11:03:56 CEST Mike Dewhirst wrote:
>
> > 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
>
> No, that's decimal.Decimal and floats being an approximation:
>
> >>> from decimal import Decimal >>> Decimal('23.45') Decimal('23.45') >>> Decimal(23.45)
> Decimal('23.449999999999999289457264239899814128875732421875')
>
> >>> print('{:.48f}'.format(23.45)) 23.449999999999999289457264239899814128875732421875 >>>
> print('{:.55f}'.format(23.45))
> 23.4499999999999992894572642398998141288757324218750000000
>
> So decimal.Decimal's constructor converts strings to decimal numbers
> with as much precision as given. It also applies to floats, except
> that floats have more precision then typed.
>
I get it :)
Thanks (again!)
Mike
> --
>
> Melvyn Sopacua
>
> --
> 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
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/4704533.IngrlRvRmB%40fritzbook
> <https://groups.google.com/d/msgid/django-users/4704533.IngrlRvRmB%40fritzbook?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
--
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/b7b0518d-0a83-2247-ad45-a149309b9d42%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment