473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3451
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mg | last post by:
Hi everybody... We try to white scripts with Pyrhon 2.4 for an acoustic simulation and we wrote these follow lines : <begin script> c = 340 i =j=k= 1 sum_ = 23 table =
6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the following: // original is a double double result =...
9
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something...
36
by: Phat G5 (G3) | last post by:
Has anyone found a reliable way to force JS to round to a specific number of places? Every time I try I get different results. For example, I'd need to round 3.4589 to 2 places. What is the most...
4
by: Fuzzydave | last post by:
I have been using a round command in a few places to round a value to zero decimal places using the following format, round('+value+', 0) but this consistantly returns the rounded result of...
4
by: lilmax88 | last post by:
I have a program in which I need to take a numeric value for dollars. There is a "set" function that must screen the value for the following 3 conditions with the indicated handling functionality:...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
0
by: Edwin.Madari | last post by:
>>round(76.1, -2) 100.0 80.0 76.0 builtin function round, will work for you...... Help on built-in function round in module __builtin__: round(...) round(number) -floating point number
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.