[Tutor] Rounding a Python float to the nearest half integer

शंतनू (Shantanoo) shantanoo at gmail.com
Mon Oct 11 10:52:27 CEST 2010


===
round(...)
    round(number[, ndigits]) -> floating point number

    Round a number to a given precision in decimal digits (default 0
digits).
    This always returns a floating point number.  Precision may be negative.
===

>>> round(1.23423,2)
1.23
>>> round(1.23623,2)
1.24


HTH.

On Mon, Oct 11, 2010 at 13:51, Sithembewena Lloyd Dube <zebra05 at gmail.com>wrote:

> Thanks everyone.
>
>
> On Fri, Oct 8, 2010 at 11:44 PM, Wayne Werner <waynejwerner at gmail.com>wrote:
>
>> On Fri, Oct 8, 2010 at 7:58 AM, Sithembewena Lloyd Dube <
>> zebra05 at gmail.com> wrote:
>>
>>> I realise that one cannot have a half integer :) I meant how would one
>>> round off to the first decimal nearest to either 0.5, or a whole number.
>>>
>>> Ugh...does anyone get what I'm trying to articulate? :)
>>
>>
>> sample input/output cases are always useful.
>>
>> -Wayne
>>
>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101011/333ba96e/attachment.html>


More information about the Tutor mailing list