|
-
Mar 9th, 2010, 02:45 PM
#1
Thread Starter
New Member
[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.
Last edited by MuscleShark88; Mar 9th, 2010 at 02:57 PM.
-
Mar 9th, 2010, 02:50 PM
#2
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
-
Mar 9th, 2010, 02:53 PM
#3
Thread Starter
New Member
Re: Really weird thing happening with my Double...
 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...
-
Mar 9th, 2010, 02:54 PM
#4
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.
-
Mar 9th, 2010, 02:56 PM
#5
Thread Starter
New Member
Re: Really weird thing happening with my Double...
i'm displaying it through a label
lblP1FirstPlacePercent.caption = FirstPlacePercent(1)
-
Mar 9th, 2010, 02:56 PM
#6
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
-
Mar 9th, 2010, 02:58 PM
#7
Thread Starter
New Member
Re: Really weird thing happening with my Double...
 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
Last edited by MuscleShark88; Mar 9th, 2010 at 03:03 PM.
-
Mar 9th, 2010, 03:03 PM
#8
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
-
Mar 9th, 2010, 03:06 PM
#9
Thread Starter
New Member
Re: Really weird thing happening with my Double...
 Originally Posted by LaVolpe
Is your label too short to display the far right of the value?

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
-
Mar 9th, 2010, 03:08 PM
#10
Re: Really weird thing happening with my Double...
You're welcome. Sometimes the easiest things are the hardest to see!
-
Mar 9th, 2010, 03:11 PM
#11
Re: Really weird thing happening with my Double...
 Originally Posted by MuscleShark88
[IMG]Assumed that it would adjust and squeeze in E-02
bad assumption 
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")
-
Mar 9th, 2010, 03:15 PM
#12
Re: Really weird thing happening with my Double...
 Originally Posted by MuscleShark88
i feel dumb
rofl thanks for the help...greatly appreciated.
i am new to VB
Muscle
Welcome to the Forums 
Glad LaVolpe got you squared away
BTW - great image. Haven't seen Jean-Luc for a while 
Spoo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|