Floor value in math operators

John Machin sjmachin at lexicon.net
Thu Apr 9 04:26:10 EDT 2009


On Apr 9, 4:18 pm, AggieDan04 <danb... at yahoo.com> wrote:
> On Apr 8, 12:08 pm, David Smith <d... at cornell.edu> wrote:
>
>
>
> > Avi wrote:
> > > Hi,
>
> > > This will be a very simple question to ask all the awesome programmers
> > > here:
>
> > > How can I get answer in in decimals for such a math operator:
>
> > > 3/2
>
> > > I get 1. I want to get 1.5
>
> > > Thanks in advance,
> > > Avi
>
> > I'm going to assume your operands are variables instead of numeric
> > literals.  Why not consider doing a type conversion to float or Decimal
> > and then perform the division?
>
> Because float(x) and Decimal(x) fail for complex numbers and lose
> precision if x is a rational or a multi-precision float.

What is the likelihood that the OP would get 3 / 2 -> 1 if he was
working with rationals or multi-precision floats?

What is the likelihood that the OP would ask such a question if he was
working with rationals or multi-precision floats?



More information about the Python-list mailing list