Olaan Expert Licensed User Longtime User Dec 28, 2024 #1 Refer to this ,I'm looking for Maths' Formulas for B4X Assume In VB : 12 \6 =2 What's that in B4X? Last edited: Dec 28, 2024
Sagenut Expert Licensed User Longtime User Dec 28, 2024 #2 Not sure but it could be B4X: Copy Log(12 Mod 6) Post other calculations example if this is not the answer. Upvote 0
Not sure but it could be B4X: Copy Log(12 Mod 6) Post other calculations example if this is not the answer.
Johan Schoeman Expert Licensed User Longtime User Dec 28, 2024 #3 Sagenut said: Not sure but it could be B4X: Copy Log(12 Mod 6) Post other calculations example if this is not the answer. Click to expand... It is an integer division. Like 17\4 = 4 17 mod 4 = 1 Upvote 0
Sagenut said: Not sure but it could be B4X: Copy Log(12 Mod 6) Post other calculations example if this is not the answer. Click to expand... It is an integer division. Like 17\4 = 4 17 mod 4 = 1
Sagenut Expert Licensed User Longtime User Dec 28, 2024 #4 Johan Schoeman said: It is an integer division. Like 17\4 = 4 17 mod 4 = 1 Click to expand... So in that case 12 \ 6 = 2. Right? Upvote 0
Johan Schoeman said: It is an integer division. Like 17\4 = 4 17 mod 4 = 1 Click to expand... So in that case 12 \ 6 = 2. Right?
Johan Schoeman Expert Licensed User Longtime User Dec 28, 2024 #5 Sagenut said: So in that case 12 \ 6 = 2. Right? Click to expand... Yes Upvote 0
Johan Schoeman Expert Licensed User Longtime User Dec 28, 2024 #6 Sagenut said: So in that case 12 \ 6 = 2. Right? Click to expand... 13\6 = 2 as well Upvote 0
Sagenut Expert Licensed User Longtime User Dec 28, 2024 #7 In this case I think that there is an error in the opening question. Upvote 0
Johan Schoeman Expert Licensed User Longtime User Dec 28, 2024 #8 Sagenut said: In this case I think that there is an error in the opening question. Click to expand... I might be wrong but from memory that is what VB does when using \ Upvote 0
Sagenut said: In this case I think that there is an error in the opening question. Click to expand... I might be wrong but from memory that is what VB does when using \
Sagenut Expert Licensed User Longtime User Dec 28, 2024 #9 What about B4X: Copy Log((11 / 4).As(Int)) or B4X: Copy Dim numb as Int = (11 / 4) Last edited: Dec 28, 2024 Upvote 0
Daestrum Expert Licensed User Longtime User Dec 28, 2024 #10 I think this gives the effect you want (a - (a mod b)) / b Upvote 0
LucaMs Expert Licensed User Longtime User Dec 28, 2024 #11 Johan Schoeman said: I might be wrong but from memory that is what VB does when using \ Click to expand... Yes, in VB there is the possibility to write the division using the slash or backslash character. Using the backslash, the whole result would be returned, discarding the remainder. In B4X: B4X: Copy Dim Result As Int Result = 13 / 2 Log(Result) '6 Upvote 0
Johan Schoeman said: I might be wrong but from memory that is what VB does when using \ Click to expand... Yes, in VB there is the possibility to write the division using the slash or backslash character. Using the backslash, the whole result would be returned, discarding the remainder. In B4X: B4X: Copy Dim Result As Int Result = 13 / 2 Log(Result) '6
LucaMs Expert Licensed User Longtime User Dec 28, 2024 #12 LucaMs said: Yes, in VB there is the possibility to write the division using the slash or backslash character. Using the backslash, the whole result would be returned, discarding the remainder. In B4X: B4X: Copy Dim Result As Int Result = 13 / 2 Log(Result) '6 Click to expand... Even so: Log((13/2).As(Int)) ' 6 Upvote 0
LucaMs said: Yes, in VB there is the possibility to write the division using the slash or backslash character. Using the backslash, the whole result would be returned, discarding the remainder. In B4X: B4X: Copy Dim Result As Int Result = 13 / 2 Log(Result) '6 Click to expand... Even so: Log((13/2).As(Int)) ' 6
toby Well-Known Member Licensed User Longtime User Dec 28, 2024 #13 It's called floor division. Here is the tested code: B4X: Copy Dim x As Int Dim y As Int = 2 Dim result As Int For x=1 To 20 result = Floor(x / y) ' Perform division and discard the fractional part Log($"${x}->${result}"$) ' Outputs: Result Next Results: 1->0 2->1 3->1 4->2 5->2 6->3 7->3 8->4 9->4 10->5 11->5 12->6 13->6 14->7 15->7 16->8 17->8 18->9 19->9 20->10 Upvote 0
It's called floor division. Here is the tested code: B4X: Copy Dim x As Int Dim y As Int = 2 Dim result As Int For x=1 To 20 result = Floor(x / y) ' Perform division and discard the fractional part Log($"${x}->${result}"$) ' Outputs: Result Next Results: 1->0 2->1 3->1 4->2 5->2 6->3 7->3 8->4 9->4 10->5 11->5 12->6 13->6 14->7 15->7 16->8 17->8 18->9 19->9 20->10
LucaMs Expert Licensed User Longtime User Dec 28, 2024 #14 toby said: result = Floor(x / y) ' Perform division and discard the fractional part Click to expand... Superfluous; try the same loop so: result = x / y Floor would be required if you declared Result as Float or Double. Last edited: Dec 28, 2024 Upvote 0
toby said: result = Floor(x / y) ' Perform division and discard the fractional part Click to expand... Superfluous; try the same loop so: result = x / y Floor would be required if you declared Result as Float or Double.
E emexes Expert Licensed User Longtime User Dec 28, 2024 #15 LucaMs said: Floor would be required if you declared Result as Float or Double. Click to expand... Or depending on what you need to happen below zero. Upvote 0
LucaMs said: Floor would be required if you declared Result as Float or Double. Click to expand... Or depending on what you need to happen below zero.
LucaMs Expert Licensed User Longtime User Dec 28, 2024 #16 emexes said: Or depending on what you need Click to expand... I need.. urgently a few million euros (only ) Upvote 0
emexes said: Or depending on what you need Click to expand... I need.. urgently a few million euros (only )
E emexes Expert Licensed User Longtime User Dec 28, 2024 #17 LucaMs said: I need.. urgently a few million euros (only ) Click to expand... I have negative euros, but you are welcome to as many of them as you'd like. Upvote 0
LucaMs said: I need.. urgently a few million euros (only ) Click to expand... I have negative euros, but you are welcome to as many of them as you'd like.
Robert Valentino Well-Known Member Licensed User Longtime User Dec 28, 2024 #18 I know this might be a little crazy but when having to do money math and want the remainder I would use longs or ints and multiple the number by 100 Dim Value1 As Int = 1300 ' $13.00 Dim Value2 As Int = 2 Dim Value3 As Int = Value1 / Value2 Dim Value4 As Int = Value3 / 100 Dim Value5 As Int = Value3 - (Value4 * 100) Log(Value3) ' Amount Log(Value4) ' Whole Dollars Log(Value5) 'Cents I'm sure not a good solution but will give you both answer and remainder in one variable Upvote 0
I know this might be a little crazy but when having to do money math and want the remainder I would use longs or ints and multiple the number by 100 Dim Value1 As Int = 1300 ' $13.00 Dim Value2 As Int = 2 Dim Value3 As Int = Value1 / Value2 Dim Value4 As Int = Value3 / 100 Dim Value5 As Int = Value3 - (Value4 * 100) Log(Value3) ' Amount Log(Value4) ' Whole Dollars Log(Value5) 'Cents I'm sure not a good solution but will give you both answer and remainder in one variable
Olaan Expert Licensed User Longtime User Dec 28, 2024 #19 I'm sorry that I wrote the incorrect answer. 12\6=2 <---correctly, Get only integer number,(notget decimal number) Upvote 0
I'm sorry that I wrote the incorrect answer. 12\6=2 <---correctly, Get only integer number,(notget decimal number)