Minus from Table Item fails, Bug or feature?
Posted: Thu May 12, 2022 12:50 pm
I wasnt able to make an example program that would have triggered this problem, therefore I am copy-pasting three lines of my code, and showing the Debugmessages, which show that something is wrong, but what?
Result, as an example:
I am suspecting if it is possible that one of these is not a number, but something else, but what can it be?
As far as I know, everything is Numbers, I have even used ReplaceStr() to remove unnecessary characters and then used ToNumber() to make them into numbers. And in Addition I even used GetType() to see that they are numbers.
Also, It seems there is no problem when I am using "+"-operator, problem is only when I use "-" operator.
In Addition, to take out the possibility of having misspelled something, i also did following:
And still result was:
Is this a Bug or a feature? Is it possible one of the numbers is not actually a number, and how can I check that if GetType didnt reveal it?
edit: Took a try to change instead of using "-" using "Sub()", but that didnt work either, but result was still the same.
edit2: Tried to trick it with following idea:
(also tried using "+" operator) but still no use, result is still the same, which is even more strange, since to show more of the code:
Point being that when it does the above ones "+" operator, there is no problem at all. It only has problem when it is doing the "-" side, and yet these two should be identical as far as I know.
Edit3:
I changed
into
and it works fine as long as both numbers are on plus side. It seems to be only having problem when subtraction happens, whether with "-" operator, or due to other number being less than 0.
Code: Select all
If CurrencyLost = "xrp" Then DebugPrint("XRP Balance: "..CoinHoldingPlaces[Place][CurrencyLost].." Lost amount: "..LostAmount)
CoinHoldingPlaces[Place][CurrencyLost] = CoinHoldingPlaces[Place][CurrencyLost] - LostAmount
If CurrencyLost = "xrp" Then DebugPrint("New Balance: "..CoinHoldingPlaces[Place][CurrencyLost])
Code: Select all
XRP Balance: 145 Lost amount: 145
New Balance: -2.7284841053188e-012
As far as I know, everything is Numbers, I have even used ReplaceStr() to remove unnecessary characters and then used ToNumber() to make them into numbers. And in Addition I even used GetType() to see that they are numbers.
Also, It seems there is no problem when I am using "+"-operator, problem is only when I use "-" operator.
In Addition, to take out the possibility of having misspelled something, i also did following:
Code: Select all
Local num1 = CoinHoldingPlaces[Place][CurrencyLost]
DebugPrint("number: "..#NUMBER)
DebugPrint("num1: "..GetType(num1).." LostAmount: "..GetType(LostAmount))
DebugPrint("num1: "..num1.." LostAmount:"..LostAmount)
Local num2 = num1 - LostAmount
DebugPrint("num1 - LostAmount: "..num2)
Code: Select all
number: 2
num1: 2 LostAmount: 2
num1: 145 LostAmount:145
num1 - LostAmount: -2.7284841053188e-012
edit: Took a try to change instead of using "-" using "Sub()", but that didnt work either, but result was still the same.
edit2: Tried to trick it with following idea:
Code: Select all
LostAmount2 = 0 - LostAmount
Add(num1, LostAmount2)
Code: Select all
If CurrencyGained <> ""
If HaveItem(CoinHoldingPlaces[Place], CurrencyGained) = False Then CoinHoldingPlaces[Place][CurrencyGained] = 0
CoinHoldingPlaces[Place][CurrencyGained] = CoinHoldingPlaces[Place][CurrencyGained] + GainedAmount
EndIf
If CurrencyLost <> ""
CoinHoldingPlaces[Place][CurrencyLost] = CoinHoldingPlaces[Place][CurrencyLost] - LostAmount
EndIf
Edit3:
I changed
Code: Select all
Local num2 = num1 - LostAmount
Code: Select all
Local num2 = num1 + LostAmount