473,569 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Mat h.Round() is not allowing me to do this.
Any help in this reagards is widely appreciated.

Thanks
Prabhakar
Nov 15 '05 #1
2 9175
Prabhakar <an*******@disc ussions.microso ft.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.Mat h.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.co m>
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*******@disc ussions.microso ft.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.Mat h.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.co m>
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
6795
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 nearest even penny using the code that follow. The problem I have is that once I set the even rounded value back to the text field it adds a 01 on the...
4
7819
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. I need it to contain 180.26. Any ideas?
11
6631
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 seems to be done like this 3.435 = 3.44 3.445 = 3.44 Dim decNbr1 As Decimal
29
3152
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
13169
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) It then updates the value with numberOfPrecisions after the decimal
20
4970
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
29500
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 expected my_round(2.5) = 2 # Not 3, which is an odd num I'm interested in rounding numbers of the form "x.5" depending upon whether x is odd...
0
7695
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.