[RESOLVED] Really weird thing happening with my Double...
I have no idea why this is happening...very strange.
Assume the following situation:
Dim FirstPlacePercent(4) as Double
Dim StackSum as Long
Dim Stack(4) as Long
txtstack1.text = 1
txtstack2.text = 50000
txtstack3.text = 50000
txtstack4.text = 50000
Stack(1) = txtstack1.text
Stack(2) = txtstack2.text
Stack(3) = txtstack3.text
Stack(4) = txtstack4.text
For i = 1 to 4
StackSum = StackSum + Stack(i)
next i
For i = 1 to 4
FirstPlacePercent(i) = (Stack(i)/StackSum) * 100
next i
____________________
ok, so since Stack(1) is VERY small relative to the others...it should yield
FirstPlacePercent(1) = .0000066666666
FirstPlacePercent(2) = 33.333
FirstPlacePercent(3) = 33.333
FirstPlacePercent(4) = 33.333
BUT for some reason that is beyond my knowledge, it is actually outputting
FirstPlacePercent(1) = 6.666666
FirstPlacePercent(2) = 33.333
FirstPlacePercent(3) = 33.333
FirstPlacePercent(4) = 33.333
anyone have any clue why this is happening? b/c i'm baffled.
Re: Really weird thing happening with my Double...
Why do you think that: FirstPlacePercent(1) = 6.6666666 ?
stacksum totals to 50000*3 + 1 or 150001
For FirstPlacePercent(1), you are dividing 1/150001 which would be 6.66662222251852E-06 or approx: 0.000006666622223
Re: Really weird thing happening with my Double...
Quote:
Originally Posted by
LaVolpe
Why do you think that: FirstPlacePercent(1) = 6.6666666 ?
stacksum totals to 50000*3 + 1 or 150001
For FirstPlacePercent(1), you are dividing 1/150001 which would be 6.66662222251852E-06 or approx: 0.000006666622223
it shouldn't be yielding 6.66666.....BUT IT IS...this is my problem....this is what the screen is outputting
i realize it should be 0.000006666 ...but it's not outputting that
and it's screwing up my equations later on...
Re: Really weird thing happening with my Double...
Double check again, do you see the E-06 at the end? If not, how are you displaying the results? Show us that.
Re: Really weird thing happening with my Double...
i'm displaying it through a label
lblP1FirstPlacePercent.caption = FirstPlacePercent(1)
Re: Really weird thing happening with my Double...
Oh, what language are you using?
VB6 Integers cannot hold a value of 50000. You should be getting an error & if you have On Error Resume Next in your routine that is your problem -- fix the error
Re: Really weird thing happening with my Double...
Quote:
Originally Posted by
LaVolpe
Oh, what language are you using?
VB6 Integers cannot hold a value of 50000. You should be getting an error & if you have On Error Resume Next in your routine that is your problem -- fix the error
using vb6
sorry about that, i actually typed out the situation wrong...
in my program i actually have:
Dim Stack(4) as Long (NOT integer like i had before)
still not working tho :(
also: if i had it:
Stack(1) = 1
Stack(2) = 400
Stack(3) = 400
Stack(4) = 400
i get the same thing.....w/ FirstPlacePercent = 8.32 instead of = 0.000832
really weird...b/c if i just type FirstPlacePercent = 0.000832 in the code , it works....but not when the code runs the program thru
Re: Really weird thing happening with my Double...
Is your label too short to display the far right of the value?
Tweak your routine like so and then open your immediate/debug window (Ctrl+G) to see what was printed out
Code:
For i = 1 To 4
FirstPlacePercent(i) = (Stack(i) / StackSum) * 100
Debug.Print i; Stack(i); StackSum, FirstPlacePercent(i)
Next i
Re: Really weird thing happening with my Double...
Quote:
Originally Posted by
LaVolpe
Is your label too short to display the far right of the value?
http://jamie-online.com/random-jamz/...6/facepalm.jpg
i feel dumb
rofl thanks for the help...greatly appreciated.
i am new to VB, i assumed that it would adjust and squeeze in E-02
bad assumption :p
Re: Really weird thing happening with my Double...
:) You're welcome. Sometimes the easiest things are the hardest to see!
Re: Really weird thing happening with my Double...
Quote:
Originally Posted by
MuscleShark88
[IMG]Assumed that it would adjust and squeeze in E-02
bad assumption :p
Labels do have an AutoSize property; you may want to play with that.
Also, you may want to play with VB's Format function.
Code:
Label1.Caption = Format(someNumber, "Percent")
Re: Really weird thing happening with my Double...
Quote:
Originally Posted by
MuscleShark88
Muscle
Welcome to the Forums :wave:
Glad LaVolpe got you squared away
BTW - great image. Haven't seen Jean-Luc for a while :thumb:
Spoo