Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: rounding values to the nearest 5 or 10

Reply
Thread Tools

Re: rounding values to the nearest 5 or 10

 
 
chaz
Guest
Posts: n/a
 
      04-27-2006
"Milsnips" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In Dev-C++, how can I make a rounding to nearest integer? Mr. Ken C++ 2 05-25-2006 12:54 PM
Re: rounding values to the nearest 5 or 10 =?ISO-8859-1?Q?G=F6ran_Andersson?= ASP .Net 1 04-28-2006 08:29 AM
Re: rounding values to the nearest 5 or 10 Greg Young [MVP] ASP .Net 0 04-27-2006 12:09 PM
Rounding up to the nearest exact logarithmic decade Derek Basch Python 8 02-28-2006 11:54 PM
rounding a float/double to nearest 1/10th Shea Martin C++ 7 10-30-2003 04:51 PM



Advertisments