Thanks Shantanoo, finally got the hang of this.
2010/10/11 शंतनू (Shantanoo)
> ===
> 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. Precisio
===
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, O
Thanks everyone.
On Fri, Oct 8, 2010 at 11:44 PM, Wayne Werner wrote:
> On Fri, Oct 8, 2010 at 7:58 AM, Sithembewena Lloyd Dube > 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.
>>
>> U
On Fri, Oct 8, 2010 at 7:58 AM, Sithembewena Lloyd Dube
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
> @Evert, I didn't figure out that your response was a solution, thought it was
> a question. Must be coffee time :P
>
> I tried it and, for instance, the rounded value (9) / 2 gave me 4.0 Couldn't
> get it until I noticed that @Joel divided the roudned figure by a decimal
> 2.0. That gave 4.5,
@Evert, I didn't figure out that your response was a solution, thought it
was a question. Must be coffee time :P
I tried it and, for instance, the rounded value (9) / 2 gave me 4.0 Couldn't
get it until I noticed that @Joel divided the roudned figure by a decimal
2.0. That gave 4.5, which is what
Thanks everyone,
I need to round to the nearest half (finally occured).
Made some chnages to Wayne's code as follows:
x = 4.4348
if x % 1 >= 0.5:
round(x) # gives 5.0 if the the value of the expression x % 1 exceeds
0.5
else:
x = round(x) + 0.5 # gives 4.5, as in this case.
Many thanks!
On Fri, Oct 8, 2010 at 9:00 AM, Evert Rol 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? :)
>
> Multiply by 2, round(), divide
> 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? :)
Multiply by 2, round(), divide by 2?
>
> On Fri, Oct 8, 2010 at 2:51 PM, Sithembewena
On Fri, Oct 8, 2010 at 7:51 AM, Sithembewena Lloyd Dube
wrote:
> Hi folks,
>
> Supposing I had the float 4.4348 and I wished to round it off to the
> nearest half-integer upwards or downwards, how would I go about it?
>
You can use round:
round(4.4348) -> 4.0
But if you want to specify the beha
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? :)
On Fri, Oct 8, 2010 at 2:51 PM, Sithembewena Lloyd Dube
wrote:
> Hi folks,
>
> Supposing I had t
Hi folks,
Supposing I had the float 4.4348 and I wished to round it off to the nearest
half-integer upwards or downwards, how would I go about it?
Many thanks...
--
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com
___
Tutor maillist - Tutor
12 matches
Mail list logo