round a number to the first 10, 50, 100

  • Thread starter Thread starter Jassim Rahma
  • Start date Start date
J

Jassim Rahma

I have a number, for example 0.152 or 1.729 and I want to allow to round to
the first 0.010 or 0.050 or 0.100
 
Jassim Rahma said:
I have a number, for example 0.152 or 1.729 and I want to allow to round to
the first 0.010 or 0.050 or 0.100

One approach:

Use the Decimal data type.

Multiply by 100, or 20, or 10.

Round to nearest integer.

Divide by the number you multipied by.

But also look for built-in rounding functions.
 
still unable to get it..

what I want is the following:

0.171 round to 10 is 0.180
0.264 round to 10 is 0.270
0.397 round to 10 is 0.400
1.993 round to 10 is 2.000

using the same logic I want to round to 50 and 100
 
Michael's method rounds to the nearest 10th, 100th, etc. If you want to
always round up, try this instead (not tested):

decimal value = 0.171;
value *= 10;
value = decimal.Ceiling(value);
value /= 10;
 
Michael's method rounds to the nearest 10th, 100th, etc. If you want to
always round up, try this instead (not tested):

decimal value = 0.171;
value *= 10;
value = decimal.Ceiling(value);
value /= 10;
 

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

Back
Top