Anjanesh Lekshminarayanan wrote:
a = 1
b = 25
a / b
0
float(a) / b
0.040001
from __future__ import division
a = 1
b = 25
a / b
0.040001
In what simple way can I get just 0.04 ?
Short answer: use 3.1:
>>> 1//25
0
>>> 1/25
0.04
;-)
But you should really try to unde
On 2009-06-19, Anjanesh Lekshminarayanan wrote:
a = 1
b = 25
a / b
> 0
float(a) / b
> 0.040001
>
from __future__ import division
a = 1
b = 25
a / b
> 0.040001
>
> In what simple way can I get just 0.04 ?
You can't. There _
Anjanesh Lekshminarayanan wrote:
a = 1
b = 25
a / b
0
float(a) / b
0.040001
from __future__ import division
a = 1
b = 25
a / b
0.040001
In what simple way can I get just 0.04 ?
Your subject line says "Integer Division" but
> Anjanesh Lekshminarayanan (AL) escribió:
> a = 1
> b = 25
> a / b
>AL> 0
> float(a) / b
>AL> 0.040001
>
> from __future__ import division
> a = 1
> b = 25
> a / b
>AL> 0.040001
>
>AL> In what simple way can I get just 0.04
On Jun 19, 8:22 am, Anjanesh Lekshminarayanan
wrote:
> >>> a = 1
> >>> b = 25
> >>> a / b
> 0
> >>> float(a) / b
>
> 0.040001
Python typically stores floats in binary, not decimal. The
value 0.04 isn't exactly representable in binary, so the
division float(1)/25 can't produce 0.04:
On Fri, Jun 19, 2009 at 12:22 AM, Anjanesh
Lekshminarayanan wrote:
a = 1
b = 25
a / b
> 0
float(a) / b
> 0.040001
>
from __future__ import division
a = 1
b = 25
a / b
> 0.040001
>
> In what simple way can I get just 0.04 ?
N
In <[EMAIL PROTECTED]>, Dan Bishop
wrote:
> On Jun 7, 8:30 pm, Some Other Guy <[EMAIL PROTECTED]> wrote:
>> Since this just involves doubling you can avoid multiplying altogether
>> and just use this:
>>
>> def rounddiv(a,b):
>> return int((a+a+b)/(b+b))
>>
>> That's 3 integer adds and 1 integer
"Some Other Guy" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| [EMAIL PROTECTED] wrote:
|
| > Hello all,
| > I have two integers and I want to divide one by another, and want to
| > get an integer result which is the higher side whenever the result is
| > a fraction.
| > 3/2 =>
On Jun 7, 8:30 pm, Some Other Guy <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hello all,
> > I have two integers and I want to divide one by another, and want to
> > get an integer result which is the higher side whenever the result is
> > a fraction.
> > 3/2 => 1 # Usual behavior
>
"Sion Arrowsmith" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
| > 3/2 => 1 # Usual behavior
| > some_func(3, 2) => 2 # Wanted
|
| def some_func(a, b):
|return -(-a/b)
|
| And people complain about Python's behaviour regarding divi
Hamish Moffatt <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] wrote:
> def div_ceil(a, b):
>> ... if a%b:
>> ... return ((a/b)+1)
>> ... else:
>> ... return (a/b)
>
>Yes, although it's not as short or as fast (probably as my version):
>
>def div_ceil(a, b):
> return
[EMAIL PROTECTED] wrote:
> On Jun 7, 2:15 pm, Hamish Moffatt <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>>> Hello all,
>>> I have two integers and I want to divide one by another, and want to
>>> get an integer result which is the higher side whenever the result is
>>> a fraction.
>>>
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 3/2 => 1 # Usual behavior
> some_func(3, 2) => 2 # Wanted
def some_func(a, b):
return -(-a/b)
And people complain about Python's behaviour regarding division of
negative integers.
--
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
On Jun 7, 2:15 pm, Hamish Moffatt <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hello all,
> > I have two integers and I want to divide one by another, and want to
> > get an integer result which is the higher side whenever the result is
> > a fraction.
> > 3/2 => 1 # Usual behavior
>
[EMAIL PROTECTED] wrote:
> Hello all,
> I have two integers and I want to divide one by another, and want to
> get an integer result which is the higher side whenever the result is
> a fraction.
> 3/2 => 1 # Usual behavior
> some_func(3, 2) => 2 # Wanted
>
> Any easier solution other than int(m
15 matches
Mail list logo