Calculate 8000 * 0.3 - 8000 * 3 / 10
Comments?
0?
Quote from: Explicit[nK] on December 15, 2005, 02:11 PM
0?
What version of VB did you use to come to that conclusion? If you did not, consider why this was posted to the VB forum... ;)
I got 0 (VB6)
I got 0 too (I used Visual basic 6).
Quote from: Adron on December 15, 2005, 02:45 PM
Quote from: Explicit[nK] on December 15, 2005, 02:11 PM
0?
What version of VB did you use to come to that conclusion? If you did not, consider why this was posted to the VB forum... ;)
Pffffft, who needs VB when you have your fingers? I counted out to 8000, and chopped off a finger to attain the three-tenths fraction, then smashed my hands together and found nothing was left. :)
Hmm, weird. I did that in VB6, and did not get 0. Just typed it in the debug window,
?8000 * 0.3 - 8000 * 3 / 10
I got -8.88178419700125E-14
[Edit]: and -1500 in a string
Quote from: Adron on December 15, 2005, 04:09 PM
Hmm, weird. I did that in VB6, and did not get 0. Just typed it in the debug window,
?8000 * 0.3 - 8000 * 3 / 10
Perhaps the debug window doesn't follow order of operations?
Wow another reason ive droped VB.
But one question. WTF!?!?!
~-~(HDX)~-~
Quote from: MyndFyre on December 15, 2005, 04:46 PM
Perhaps the debug window doesn't follow order of operations?
Well, it originally came from a larger program. So it's not just the debug window.
Quote from: Adron on December 15, 2005, 01:23 PM
Calculate 8000 * 0.3 - 8000 * 3 / 10
Comments?
'VB6
Private Sub Form_Load()
Dim a As Double
Dim b As Double
Dim x As Double
Dim y As Double
a = 8000 * 0.3 '2400
b = 8000 * 3 / 10 '2400
x = a - b
y = 8000 * 0.3 - 8000 * 3 / 10
Debug.Print x 'Real answer
'= 0
Debug.Print y 'Real Problem
'= -8.88178419700125E-14
End Sub
Is this problem only with subtraction? (Addition works fine.)
I guess the solution to this is to create your own calculation processor.
Currency can do it all in one:
Const Zero As Currency = 8000 * 0.3 - 8000 * 3 / 10
Quote from: Ringo on December 15, 2005, 11:10 PM
Currency can do it all in one:
Const Zero As Currency = 8000 * 0.3 - 8000 * 3 / 10
Currency can't handle the size of the answer so it rounds to zero. I'll give you another test for that though:
Const Answer As Currency = Fix(8000 * 0.3)
hmm, what about CDec(CDbl(8000 * 0.3) - CDbl(8000 * 3 / 10))?
You don't suppose VB uses its own floating-point library from the days that most computers didn't have coprocessors, do you?
Sub form_load()
Dim a#, b#, c#, d#
a = (8000 * 0.3)
b = 8000 * 3
c = b / 10
d = a - c
Text1.Text = d
'Answer = 0
End Sub
Quote from: l2k-Shadow on December 17, 2005, 07:18 PM
I just used
Sub form_load()
Dim a As Double
a = 8000 * 0.3 - 8000 * 3 / 10
Text1.Text = a
End Sub
and got -8.88178419700125E-14 .. what's the problem?
The problem is that it returns the wrong answer, it should be 0.
Quote from: FrOzeN on December 17, 2005, 07:22 PM
Quote from: l2k-Shadow on December 17, 2005, 07:18 PM
I just used
Sub form_load()
Dim a As Double
a = 8000 * 0.3 - 8000 * 3 / 10
Text1.Text = a
End Sub
and got -8.88178419700125E-14 .. what's the problem?
The problem is that it returns the wrong answer, it should be 0.
Yeah I just realized that, edited my post.
Question: What order does it do it in?
I cant produce that answer doing it in any order.
Quote from: 111787 on December 17, 2005, 09:10 PM
Question: What order does it do it in?
I cant produce that answer doing it in any order.
Regular math evaluation order... And copying the expression exactly as I typed it should give the nonzero result.
What I was originally doing was take 30% of an input value, and round it down to the nearest integer, i.e. Fix(x * 0.30), and this turned out to be 2399 for the input 8000. Which I thought was kinda odd...
which would be
Parenthesees
Exponents
Multiplication
Division
Addition
Subtraction
Quote from: Adron on December 18, 2005, 12:52 AM
Quote from: 111787 on December 17, 2005, 09:10 PM
Question: What order does it do it in?
I cant produce that answer doing it in any order.
Regular math evaluation order... And copying the expression exactly as I typed it should give the nonzero result.
What I was originally doing was take 30% of an input value, and round it down to the nearest integer, i.e. Fix(x * 0.30), and this turned out to be 2399 for the input 8000. Which I thought was kinda odd...
1/3 is 0.333333
Quote from: rabbit on December 18, 2005, 02:39 PM
Quote from: Adron on December 18, 2005, 12:52 AM
Quote from: 111787 on December 17, 2005, 09:10 PM
Question: What order does it do it in?
I cant produce that answer doing it in any order.
Regular math evaluation order... And copying the expression exactly as I typed it should give the nonzero result.
What I was originally doing was take 30% of an input value, and round it down to the nearest integer, i.e. Fix(x * 0.30), and this turned out to be 2399 for the input 8000. Which I thought was kinda odd...
1/3 is 0.333333
Where are you even getting 1/3 from?
I have no clue...I guess I was spacing out..
O well, it was a random fun fact I guess :P
Quote from: rabbit on December 18, 2005, 06:30 PM
I have no clue...I guess I was spacing out..
O well, it was a random fun fact I guess :P
Silly rabbit, fun facts are for kids! :)
Wow. That wasn't funny the first time. Nor the second time. Why the hell would it be funny the seven hundred twenty first time?
How is this hard. The equation is basically the same on both sides. The rule is PEMDAS stated above, Parenthesis, Exponents, Multiplication OR Division (Left to Right), Addition OR Subtraction(Left to Right).
The original equation: 8000 × 0.3 - 8000 × 3 / 10
- Since PEMDAS goes in order from Multiplication OR division from Left to Right, the "× 3 / 10" means × 0.3
The equation basically says:
= (8000 × 0.3) - (8000 × 0.3)
= 0
Why is it necessary to go in such depth?
Quote from: iNsaNe on March 05, 2006, 04:37 PM
How is this hard. The equation is basically the same on both sides. The rule is PEMDAS stated above, Parenthesis, Exponents, Multiplication OR Division (Left to Right), Addition OR Subtraction(Left to Right).
The original equation: 8000 × 0.3 - 8000 × 3 / 10
- Since PEMDAS goes in order from Multiplication OR division from Left to Right, the "× 3 / 10" means × 0.3
The equation basically says:
= (8000 × 0.3) - (8000 × 0.3)
= 0
Why is it necessary to go in such depth?
don't bring up 1 month+ old topics please