Re: Rounding

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

  1. 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() ?


    --
    Vladimir Rusinov
    GreenMice Solutions: IT-Ñ€ÐµÑˆÐµÐ½Ð¸Ñ Ð½Ð° базе Linux
    http://greenmice.info/
    Vladimir Rusinov, Dec 18, 2007
    #1
    1. Advertising

  2. Vladimir Rusinov

    John Machin Guest

    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
    #2
    1. Advertising

  3. Vladimir Rusinov

    Chris Guest

    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() ?
    >
    > --
    > Vladimir Rusinov
    > 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
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    12
    Views:
    1,860
  2. valentin tihomirov

    rounding to integer

    valentin tihomirov, Feb 15, 2004, in forum: VHDL
    Replies:
    2
    Views:
    9,519
    Jonathan Bromley
    Feb 16, 2004
  3. C

    Rounding Numbers

    C, Aug 25, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    485
  4. Thor W Hammer

    Formatting a number without rounding

    Thor W Hammer, Nov 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    491
    Karl Seguin
    Nov 22, 2005
  5. iksrazal
    Replies:
    1
    Views:
    724
    Chris Smith
    Jul 3, 2003
Loading...

Share This Page