471,355 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

round a number to the first 10, 50, 100

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

Jul 12 '07 #1
4 3202
"Jassim Rahma" <jr****@hotmail.comwrote in message
news:88**********************************@microsof t.com...
>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.
Jul 12 '07 #2
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 A. Covington" <lo**@ai.uga.edu.for.addresswrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
"Jassim Rahma" <jr****@hotmail.comwrote in message
news:88**********************************@microsof t.com...
>>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.
Jul 16 '07 #3
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;
"Jassim Rahma" <jr****@hotmail.comwrote in message
news:29**********************************@microsof t.com...
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 A. Covington" <lo**@ai.uga.edu.for.addresswrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>"Jassim Rahma" <jr****@hotmail.comwrote in message
news:88**********************************@microso ft.com...
>>>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.
Jul 16 '07 #4
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;
"Jassim Rahma" <jr****@hotmail.comwrote in message
news:29**********************************@microsof t.com...
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 A. Covington" <lo**@ai.uga.edu.for.addresswrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>"Jassim Rahma" <jr****@hotmail.comwrote in message
news:88**********************************@microso ft.com...
>>>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.
Jul 16 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by mg | last post: by
6 posts views Thread by ng_mr | last post: by
9 posts views Thread by Ronald W. Roberts | last post: by
36 posts views Thread by Phat G5 (G3) | last post: by
4 posts views Thread by Fuzzydave | last post: by
4 posts views Thread by =?Utf-8?B?UmVuZQ==?= | last post: by
reply views Thread by Edwin.Madari | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.