-
Apr 9th, 2014, 05:38 PM
#1
Thread Starter
New Member
[RESOLVED] Problems displaying numbers lower than zero
Hello, I've been working on a program to work out hypergeometric distribution (likeliness as a percentage), but I seem to constantly encounter a problem when it comes to displaying the value for the end result in a listbox (the number is around 0.3 but displays as 0). I have tried multiplying the number by 100 however it still displays as zero. Apologies for my sloppy code in advance.
Code:
'Placeholder for counting factorials
Dim placeholder1 As System.Numerics.BigInteger = 0
Dim placeholder2 As System.Numerics.BigInteger = 0
Dim placeholder3 As System.Numerics.BigInteger = 0
Dim placeholder4 As System.Numerics.BigInteger = 0
Dim placeholder5 As System.Numerics.BigInteger = 0
Dim placeholder6 As System.Numerics.BigInteger = 0
Dim placeholder7 As System.Numerics.BigInteger = 0
Dim placeholder8 As System.Numerics.BigInteger = 0
Dim placeholder9 As System.Numerics.BigInteger = 0
Dim placeholder10 As System.Numerics.BigInteger = 0
Dim placeholder11 As System.Numerics.BigInteger = 0
Dim placeholder12 As System.Numerics.BigInteger = 0
Dim placeholder13 As System.Numerics.BigInteger = 0
Dim placeholder14 As System.Decimal = 0
Code:
'First Calculation
placeholder10 = placeholder1 / (placeholder2 * placeholder3)
ListBox4.Items.Add(placeholder10)
'Second Calculation
placeholder11 = placeholder4 / (placeholder5 * placeholder6)
ListBox4.Items.Add(placeholder11)
'Third Calculation
placeholder12 = placeholder7 / (placeholder8 * placeholder9)
ListBox4.Items.Add(placeholder12)
'Final Calculation
placeholder13 = placeholder10 * placeholder11
ListBox4.Items.Add(placeholder13)
placeholder14 = placeholder13 / placeholder12
ListBox4.Items.Add(placeholder14)
The maths and the numbers work fine in the previous calculations used in placeholders 1 - 9. The output of placeholder 10 is 3, 11 is 66045, and 13 is 658008, as they should be. They all give the correct output in the listbox, but placeholder14, which should give a value of around 0.3 give out 0, even when I change the code to multiply placeholder14 by 100.
Any idea where I'm going wrong?
-
Apr 9th, 2014, 06:04 PM
#2
Re: Problems displaying numbers lower than zero
integers are whole numbers.
0.3 is a fractional number, and it is rounded when stored in an integer
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2014, 06:09 PM
#3
Thread Starter
New Member
Re: Problems displaying numbers lower than zero
I've tried changing placeholder14 to double and system.decimal, but it still only gives out 0. Is there something specific I need to declare it as, or do I need to change what I declare the rest of the variables as?
-
Apr 9th, 2014, 07:03 PM
#4
Re: Problems displaying numbers lower than zero
Originally Posted by shortymike123
I've tried changing placeholder14 to double and system.decimal, but it still only gives out 0. Is there something specific I need to declare it as, or do I need to change what I declare the rest of the variables as?
What about placeholder10 , placeholder11 and placeholder12? They all store the result of a division so what's the chance that they are all whole numbers? Anything that needs to store a value that might not be a whole number needs to be declared as a type that can hold such a value.
Why are you using BigInteger to begin with? Do you really need to be able to work with numbers too big for Long, Double or Decimal? If you just declare everything as Double or Decimal then it will probably work. There are some variables there that could probably be Integer or Long but if you don't know which ones then it's probably safer just to make everything Double or Decimal.
-
Apr 9th, 2014, 07:28 PM
#5
Re: Problems displaying numbers lower than zero
Also, try putting a break point at this line,
Code:
ListBox4.Items.Add(placeholder14)
Then check the value of the various variables. they might not contain what you think
-
Apr 10th, 2014, 06:08 PM
#6
Thread Starter
New Member
Re: Problems displaying numbers lower than zero
Thanks for the help folks! I changed placeholder11-14 to double, and it appears to do exactly what I need.
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
|