# Re: Rounding

Discussion in 'Python' started by Vladimir Rusinov, Dec 18, 2007.

On 12/15/07, katie smith <> wrote:
>
> if i have a number 6.345 and i wanted it to be 6 without subtracting .345
> because it won't always be .345 what do i do?
>
> how do i round to the nearest whole number. Or in this case round down. Is
> there an easy way to round down to the nearest whole number?

init() ?

--
GreenMice Solutions: IT-Ñ€ÐµÑˆÐµÐ½Ð¸Ñ Ð½Ð° Ð±Ð°Ð·Ðµ Linux
http://greenmice.info/

2. ### John MachinGuest

On Dec 18, 7:53 pm, "Vladimir Rusinov" <>
wrote:
> On 12/15/07, katie smith <> wrote:
>
>
>
> > if i have a number 6.345 and i wanted it to be 6 without subtracting .345
> > because it won't always be .345 what do i do?

>
> > how do i round to the nearest whole number. Or in this case round down. Is
> > there an easy way to round down to the nearest whole number?

>
> init() ?

Perhaps you mean int. The OP may also be interested in another built-
in function, just in case a float result or more versatility is
needed; it's called round.

John Machin, Dec 18, 2007

3. ### ChrisGuest

On Dec 18, 10:53 am, "Vladimir Rusinov" <>
wrote:
> On 12/15/07, katie smith <> wrote:
>
>
>
> > if i have a number 6.345 and i wanted it to be 6 without subtracting .345
> > because it won't always be .345 what do i do?

>
> > how do i round to the nearest whole number. Or in this case round down. Is
> > there an easy way to round down to the nearest whole number?

>
> init() ?
>
> --
> GreenMice Solutions: IT-ÒÅÛÅÎÉÑ ÎÁ ÂÁÚÅ Linuxhttp://greenmice.info/

You can either do:

input_number = 6.345
from math import floor
floor( input_number )
>>> 6.0

"""This will return a float rounded down.

or alternatively"""
int( input_number )
>>> 6

"""Which will return an integer data-type."""

Chris, Dec 18, 2007