Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-29 Thread Cal Leeming [Simplicity Media Ltd]
Thanks for explaining this Geoff. My math is somewhat basic, so it's always good to learn new things like this. On 29 Jun 2011 08:00, "Geoff Kuenning" wrote: > > > On Jun 29, 1:37 am, Tom Evans wrote: >> Damn, this was the bit I meant to comment upon - hard and fast rules >> are dangerous. Integr

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-29 Thread Cal Leeming
Thanks for explaining this Geoff. My math is somewhat basic, so it's always good to learn new things like this. On 29 Jun 2011 08:00, "Geoff Kuenning" wrote: > > > On Jun 29, 1:37 am, Tom Evans wrote: >> Damn, this was the bit I meant to comment upon - hard and fast rules >> are dangerous. Integr

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-29 Thread Geoff Kuenning
On Jun 29, 1:37 am, Tom Evans wrote: > Damn, this was the bit I meant to comment upon - hard and fast rules > are dangerous. Integral types are distinctly different to floating > point types, and you should be aware of which one you are using and > why. You definitely should not be using floats

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread william ratcliff
I've been trying django-money for this reason... On Jun 28, 2011 9:50 AM, "Cal Leeming [Simplicity Media Ltd]" < cal.leem...@simplicitymedialtd.co.uk> wrote: > On Tue, Jun 28, 2011 at 2:47 PM, Tom Evans wrote: > >> On Tue, Jun 28, 2011 at 2:41 PM, Cal Leeming [Simplicity Media Ltd] >> wrote: >> >

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Cal Leeming [Simplicity Media Ltd]
On Tue, Jun 28, 2011 at 2:47 PM, Tom Evans wrote: > On Tue, Jun 28, 2011 at 2:41 PM, Cal Leeming [Simplicity Media Ltd] > wrote: > > Yeah I have come up against horrible problems before when forcibly > > re-casting all int's to float's.. (especially when it's in the monetary > > sense). I had as

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Tom Evans
On Tue, Jun 28, 2011 at 2:41 PM, Cal Leeming [Simplicity Media Ltd] wrote: > Yeah I have come up against horrible problems before when forcibly > re-casting all int's to float's.. (especially when it's in the monetary > sense). I had assumed that it would be a on a "per case" basis, but just > wan

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Masklinn
On 2011-06-28, at 15:39 , Tom Evans wrote: > On Tue, Jun 28, 2011 at 2:36 PM, Masklinn wrote: >> On 2011-06-28, at 15:31 , Tom Evans wrote: >>> >>> Bit OT, but I'll bite (doesn't really relate to Django). Dividing two >>> ints ALWAYS returns an int. >> Unless you've switched to Python 3, or imp

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Cal Leeming [Simplicity Media Ltd]
On Tue, Jun 28, 2011 at 2:37 PM, Tom Evans wrote: > On Tue, Jun 28, 2011 at 2:23 PM, Cal Leeming [Simplicity Media Ltd] > wrote: > > I'm wondering if it's better practise to always cast a number as a > > float/decimal, rather than an int. > > Any thoughts guys? > > Cal > > > > Damn, this was the

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Cal Leeming [Simplicity Media Ltd]
Ah, I didn't know about importing division from __future__, so I may use this, thanks for letting me know! On Tue, Jun 28, 2011 at 2:36 PM, Masklinn wrote: > On 2011-06-28, at 15:31 , Tom Evans wrote: > > > > Bit OT, but I'll bite (doesn't really relate to Django). Dividing two > > ints ALWAYS r

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Tom Evans
On Tue, Jun 28, 2011 at 2:36 PM, Masklinn wrote: > On 2011-06-28, at 15:31 , Tom Evans wrote: >> >> Bit OT, but I'll bite (doesn't really relate to Django). Dividing two >> ints ALWAYS returns an int. > Unless you've switched to Python 3, or imported division from __future__ in > which case true

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Cal Leeming [Simplicity Media Ltd]
Yeah I'm aware of this now, but it was more of a "oh, didn't ever notice this before" rather than a "why is this happening" thread :) I was expecting that dividing two ints would return a float, but it doesn't. It does make sense, just a bit of a gotcha, you know? Cal On Tue, Jun 28, 2011 at 2:3

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Tom Evans
On Tue, Jun 28, 2011 at 2:23 PM, Cal Leeming [Simplicity Media Ltd] wrote: > I'm wondering if it's better practise to always cast a number as a > float/decimal, rather than an int. > Any thoughts guys? > Cal > Damn, this was the bit I meant to comment upon - hard and fast rules are dangerous. Int

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Masklinn
On 2011-06-28, at 15:31 , Tom Evans wrote: > > Bit OT, but I'll bite (doesn't really relate to Django). Dividing two > ints ALWAYS returns an int. Unless you've switched to Python 3, or imported division from __future__ in which case true division is the default, and integer division is bumped to

Re: Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Tom Evans
On Tue, Jun 28, 2011 at 2:23 PM, Cal Leeming [Simplicity Media Ltd] wrote: > So, today I was confused why on earth dividing two ints (which leaves a > remainder), didn't return back an int. > In the end, I re-casted the ints as floats, performed the division, and this > worked fine. > Looked throu

Curious int/float/division/math 'gotcha' in py (discussion)

2011-06-28 Thread Cal Leeming [Simplicity Media Ltd]
So, today I was confused why on earth dividing two ints (which leaves a remainder), didn't return back an int. In the end, I re-casted the ints as floats, performed the division, and this worked fine. Looked through the docs, and found this: http://docs.python.org/library/stdtypes.html *"For (pl