Re: rounding to 9's



On Sat, 07 Jul 2007 14:46:36 -0700, "Mark S. Milley, MCSD
(BinarySwitch)" <mark.milley@xxxxxxxxxxxxxxxx> wrote:

Hi Joregen -

How are you getting 4 down and 5 up? Last time I checked, we were
using base ten.

Numbers ending in 0-4 are rounded down, 5-9 are rounded up; 5 on each
side.

Thanks,

-Mark

I said 5 down, 4 up, and the last could go either way.

Because you are using simple Math.Round, which will round off 5s
to the nearest *even* value, e.g. 2.5 becomes 2, 3.5 becomes 4,
4.5 becomes 4, 5.5 becomes 6, and so on. That is great if that
is what you want, but I presumed it did not apply to the original
poster's needs.

Here is your suggestion wrapped in a test program:
---snip---
Private Sub RoundingTest()
Dim ups As Integer = 0
Dim downs As Integer = 0
Dim totalcount As Integer = 0
For value As Decimal = 1D To 1.99D Step 0.01D
Dim roundedvalue As Decimal = Math.Round(value, 1) - 0.01D
Debug.WriteLine(value.ToString("0.00") & ": " &
roundedvalue.ToString("0.00"))
totalcount = totalcount + 1
If roundedvalue < value Then
downs = downs + 1
Else
ups = ups + 1
End If
Next

Debug.WriteLine("------------------------")
Debug.WriteLine("Total: " & totalcount.ToString)
Debug.WriteLine("Ups: " & ups.ToString)
Debug.WriteLine("Downs: " & downs.ToString)

End Sub
---snip---

The results are below: 55 values rounded down, 45 rounded
up.

You can read about various rounding methods here:
http://en.wikipedia.org/wiki/Rounding

Go watch Superman III for another lesson in rounding.

Regards,

Joergen Bech

---snip---
1,00: 0,99
1,01: 0,99
1,02: 0,99
1,03: 0,99
1,04: 0,99
1,05: 0,99
1,06: 1,09
1,07: 1,09
1,08: 1,09
1,09: 1,09
1,10: 1,09
1,11: 1,09
1,12: 1,09
1,13: 1,09
1,14: 1,09
1,15: 1,19
1,16: 1,19
1,17: 1,19
1,18: 1,19
1,19: 1,19
1,20: 1,19
1,21: 1,19
1,22: 1,19
1,23: 1,19
1,24: 1,19
1,25: 1,19
1,26: 1,29
1,27: 1,29
1,28: 1,29
1,29: 1,29
1,30: 1,29
1,31: 1,29
1,32: 1,29
1,33: 1,29
1,34: 1,29
1,35: 1,39
1,36: 1,39
1,37: 1,39
1,38: 1,39
1,39: 1,39
1,40: 1,39
1,41: 1,39
1,42: 1,39
1,43: 1,39
1,44: 1,39
1,45: 1,39
1,46: 1,49
1,47: 1,49
1,48: 1,49
1,49: 1,49
1,50: 1,49
1,51: 1,49
1,52: 1,49
1,53: 1,49
1,54: 1,49
1,55: 1,59
1,56: 1,59
1,57: 1,59
1,58: 1,59
1,59: 1,59
1,60: 1,59
1,61: 1,59
1,62: 1,59
1,63: 1,59
1,64: 1,59
1,65: 1,59
1,66: 1,69
1,67: 1,69
1,68: 1,69
1,69: 1,69
1,70: 1,69
1,71: 1,69
1,72: 1,69
1,73: 1,69
1,74: 1,69
1,75: 1,79
1,76: 1,79
1,77: 1,79
1,78: 1,79
1,79: 1,79
1,80: 1,79
1,81: 1,79
1,82: 1,79
1,83: 1,79
1,84: 1,79
1,85: 1,79
1,86: 1,89
1,87: 1,89
1,88: 1,89
1,89: 1,89
1,90: 1,89
1,91: 1,89
1,92: 1,89
1,93: 1,89
1,94: 1,89
1,95: 1,99
1,96: 1,99
1,97: 1,99
1,98: 1,99
1,99: 1,99
------------------------
Total: 100
Ups: 45
Downs: 55








.



Relevant Pages

  • Re: rounding to 9s
    ... Dim ups As Integer = 0 ... Dim downs As Integer = 0 ... Dim totalcount As Integer = 0 ...
    (microsoft.public.dotnet.languages.vb)
  • Re: rounding to 9s
    ... Dim ups As Integer = 0 ... Dim downs As Integer = 0 ... Dim totalcount As Integer = 0 ...
    (microsoft.public.dotnet.languages.vb)