473,386 Members | 1,795 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,386 software developers and data experts.

Rounding functions

Hi, I have a list of numbers I would like to round to different
decimals based on the value of the number. I would use a select case
to do this but I am not sure how to round to set values. For example:

number is between 1-2, round to nearest 0.01
number is between 2-3, round to nearest 0.02
number is between 3-4, round to nearest 0.05
number is between 4-6, round to nearest 0.1

would I need to strip the decimal from the whole number and perform
functions on the decimal part or are there any ready made functions
that can do this?

Thanks,

Mike

Nov 21 '05 #1
4 1219
found the answer:

http://www.freevbcode.com/ShowCode.asp?ID=1558

Nov 21 '05 #2
Remember that solution was intended for VB5/6 and made use of Doubles. You
should change all the doubles to decimal to retain precision in .Net.
"Mike" <my***@pearcey2001.freeserve.co.uk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
found the answer:

http://www.freevbcode.com/ShowCode.asp?ID=1558

Nov 21 '05 #3
thanks :-)

Nov 21 '05 #4
Can't you use the Round method of the Decimal class, like:

myRoundedDecimal = Decimal.Round (mydecimal, NoOfSignificantDigits)
--
Dennis in Houston
"Mike" wrote:
thanks :-)

Nov 21 '05 #5

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

Similar topics

14
by: calan | last post by:
Does anyone have a function that will round a number to 0 or .5? I have a form where I'm entering a number in inches. I need to round it to the nearest 1/2 inch (onChange). The split will be...
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. ...
2
by: Keith | last post by:
Hello, Let's say Textbox1.text = 10 size = 46 answer = (Val(TextBox1.Text) * 100.5) / size TextBox2.Text = Format(answer, "#######.000") The answer is: 21.847830... However, when I get the...
6
by: cj | last post by:
I'm using label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString() courtesy of Marina to display how long a piece of code has taken. It's been less than a second so far but might...
5
by: Jason | last post by:
I am having a rounding problem in a value i am trying to display in VB.NET. If I have the following code: Dim x As Single = 2726.795 Dim y As Single = Math.Round(2726.795, 2) Dim s as String =...
5
by: Cygnus | last post by:
Sorry in advance for the lack of formatting in this posting. Data: (column headers) Net Sales | Royalty Rate | Total Royalty (data) 4.31 | 50.00% | 2.15 19.35 | 50.00% | 9.68
2
by: backwards15 | last post by:
Having a bit of trouble with rounding and math.sqrt. I have below a small function that generates a 4 diget code from the square root of the date. Public Function Generate() As String Dim n...
6
by: abcd | last post by:
I am trying to write a rounding function. Rounding to 0.05. e.g. I should get below results 6.125 --6.15 1.699 --1.7 1.1985 --1.20 0.5625 --0.60 Can someone have any sample for...
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>
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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.