Re: rounding values to the nearest 5 or 10

  • Thread starter =?ISO-8859-1?Q?G=F6ran_Andersson?=
  • Start date
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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?

thanks,
Paul

Divide the value by five, round it to the nearest integer, then multiply
it by five.

Example:

double x = 147.24
int y = (int)Math.Round(x / 5.0) * 5;

(This will of course round the number to 145, not 150 as you used in
your example.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top