473,387 Members | 3,781 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,387 software developers and data experts.

Rounding off a number

Hi all,
I have a function that does some calculations and returns
a value.Before i return i need to round it off to it's
nearest whole number based on the value in the hundreth
position i.e. for example if the value is 1042 i need to
return 1000 and if the value is 1090 i need to return
1050.System.Math.Round() is not allowing me to do this.
Any help in this reagards is widely appreciated.

Thanks
Prabhakar
Nov 15 '05 #1
2 9168
Prabhakar <an*******@discussions.microsoft.com> wrote:
I have a function that does some calculations and returns
a value.Before i return i need to round it off to it's
nearest whole number based on the value in the hundreth
position i.e. for example if the value is 1042 i need to
return 1000 and if the value is 1090 i need to return
1050.System.Math.Round() is not allowing me to do this.
Any help in this reagards is widely appreciated.


Why would you return 1050 for 1090 but not for 1042? Is the idea that
you *always* round down, but only to multiples of 50? If so, just:

int rounded = (original/50)*50;

should work. You should decide exactly what you want it to do for
negative numbers if they might crop up though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Thanks.I have to return 1050 for 1090 because the value
in the hundredth position is greater than 5 and for 1042
i have to return 1000 because the value in the hundredth
position is less than 5.I think your suggestion should be
fine.Will take care of the croping of the negative
numbers.

thanks
Prabhakar
-----Original Message-----
Prabhakar <an*******@discussions.microsoft.com> wrote:
I have a function that does some calculations and returns a value.Before i return i need to round it off to it's
nearest whole number based on the value in the hundreth position i.e. for example if the value is 1042 i need to return 1000 and if the value is 1090 i need to return
1050.System.Math.Round() is not allowing me to do this.
Any help in this reagards is widely appreciated.
Why would you return 1050 for 1090 but not for 1042? Is

the idea thatyou *always* round down, but only to multiples of 50? If so, just:
int rounded = (original/50)*50;

should work. You should decide exactly what you want it to do fornegative numbers if they might crop up though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Caesar Augustus | last post by:
Hello Tom, Long time listener, first time caller... I have been working with vb code to automate a salary increase process that not only rounds to the nearest penny but also rounds to the...
4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
11
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...
29
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
206
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) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
30
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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: 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...
0
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...
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...

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.