obscure Member Licensed User Longtime User Aug 16, 2013 #1 Hi there! Consider the following lines of code: Dim subtract As Long=90*24*60*60*1000 Log(subtract) This will output: -813934592 If I do it like this: Dim subtract2 As Long=90*24*60*60 subtract2=subtract2*1000 I get the correct value of 7776000000. Why is that? regards, obscure
Hi there! Consider the following lines of code: Dim subtract As Long=90*24*60*60*1000 Log(subtract) This will output: -813934592 If I do it like this: Dim subtract2 As Long=90*24*60*60 subtract2=subtract2*1000 I get the correct value of 7776000000. Why is that? regards, obscure
Erel B4X founder Staff member Licensed User Longtime User Aug 16, 2013 #2 When your calculations are done with Ints then the result will also be an integer (unless there is a division which will return a Double result). So you need to explicitly set one of the numbers to Long.
When your calculations are done with Ints then the result will also be an integer (unless there is a division which will return a Double result). So you need to explicitly set one of the numbers to Long.
A aarondc Member Licensed User Longtime User Aug 17, 2013 #3 Would this work? Dim subtract2 As Long=90*24*60*60.0
Erel B4X founder Staff member Licensed User Longtime User Aug 18, 2013 #4 Not exactly. The calculation will be done with Doubles. The result in this case will be correct however there might be cases where the result is inaccurate as not all long values can be represented accurately with a double.
Not exactly. The calculation will be done with Doubles. The result in this case will be correct however there might be cases where the result is inaccurate as not all long values can be represented accurately with a double.
obscure Member Licensed User Longtime User Aug 21, 2013 #5 Hi Erel. Thanks for the insight! cheers, obscure