Re: rounding values to the nearest 5 or 10

Discussion in 'ASP .Net' started by chaz, Apr 27, 2006.

  1. chaz

    chaz Guest

    "Milsnips" <> wrote in message
    news:%...
    > hi there,
    >
    > any help with this one? i have say, numbers which i'd like to be rounded
    > to the nearest 5 or 10, example:
    >
    > 147.24 -->>150
    > 181.99 -->> 180
    > 824.18 -->>825
    > 822.49 -->>820
    >
    > and so on.. is there anything that i can do this right away in .net or
    > would i have to somehow create my own little rounding function for this?


    The rounding function isn't hard.

    static int round5(float x)
    {
    return (x % 5) >= 2.5 ? (int)(x / 5) * 5 + 5 : (int)(x / 5) * 5;
    }

    I count a worse case scenario of 5 cpu ops, which is probably a good deal
    less than the stack frame cost.
    chaz, Apr 27, 2006
    #1
    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. Greg Young [MVP]

    Re: rounding values to the nearest 5 or 10

    Greg Young [MVP], Apr 27, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    465
    Greg Young [MVP]
    Apr 27, 2006
  2. =?ISO-8859-1?Q?G=F6ran_Andersson?=

    Re: rounding values to the nearest 5 or 10

    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Apr 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    8,190
    Milsnips
    Apr 28, 2006
  3. Shea Martin
    Replies:
    7
    Views:
    3,544
    P.J. Plauger
    Oct 30, 2003
  4. Derek Basch
    Replies:
    8
    Views:
    407
    Fredrik Lundh
    Feb 28, 2006
  5. Mr. Ken
    Replies:
    2
    Views:
    622
    Tomás
    May 25, 2006
Loading...

Share This Page