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 4 3653
Check out Math.Round http://msdn2.microsoft.com/en-us/lib...0k(VS.80).aspx
"Milsnips" <mi******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl... 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
"Milsnips" <mi******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl... 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.
> 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.)
yep, thats right, just what i was after! thanks alot.
regards,
Paul.
"Göran Andersson" <gu***@guffa.com> wrote in message
news:uk**************@TK2MSFTNGP05.phx.gbl... 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.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: b |
last post by:
Hello all, we have a table that is part of our accounting package that
stores decimals as such: 123.45678.
However the reporting standards with the accounting system display that as
123.45 note...
|
by: Zorpiedoman |
last post by:
Howcome:
Dim D as decimal = .5D
msgbox d.Round(D, 0)
this returns "0"
Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!!
Documentation says this, but what the heck are...
|
by: Jeff Boes |
last post by:
(asked last week on .questions, no response)
Can anyone explain why this happens? (under 7.4.1)
select '2004-05-27 09:00:00.500001-04' :: timestamp(0) ;
timestamp
---------------------...
|
by: 6tc1 |
last post by:
Hi all, I just discovered a rounding error that occurs in C#. I'm sure
this is an old issue, but it is new to me and resulted in a fair amount
of time trying to track down the issue.
Basically...
|
by: cj |
last post by:
Lets assume all calculations are done with decimal data types so things
are as precise as possible.
When it comes to the final rounding to cut a check to pay dividends for
example in VB rounding...
|
by: Marco |
last post by:
Hello,
I have :
float f = 36.09999999;
When I do :
char cf;
sprintf(cf,"%0.03lf", f);
I get : 36.100
|
by: Spoon |
last post by:
Hello everyone,
I don't understand how the lrint() function works.
long lrint(double x);
The function returns the nearest long integer to x, consistent with the
current rounding mode. It...
|
by: md |
last post by:
Hi
Does any body know, how to round a double value with a specific number
of digits after the decimal points?
A function like this:
RoundMyDouble (double &value, short numberOfPrecisions)
...
|
by: bdsatish |
last post by:
The built-in function round( ) will always "round up", that is 1.5 is
rounded to 2.0 and 2.5 is rounded to 3.0.
If I want to round to the nearest even, that is
my_round(1.5) = 2 # As...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |