Pedro Caldeira Active Member Licensed User Longtime User Oct 16, 2020 #1 Hello guys, Is there any way to perform a calculation with the elements in a string for instance, i have "2x10/20" it can be any other calculus, like "(234/403)-20*50" but they are string can I somehow convert them to numbers to perform the operations ? Thanks
Hello guys, Is there any way to perform a calculation with the elements in a string for instance, i have "2x10/20" it can be any other calculus, like "(234/403)-20*50" but they are string can I somehow convert them to numbers to perform the operations ? Thanks
stevel05 Expert Licensed User Longtime User Oct 16, 2020 #2 Have you seen this : https://www.b4x.com/android/forum/threads/b4x-eval-expressions-evaluator.54629/post-343073 Upvote 0
Have you seen this : https://www.b4x.com/android/forum/threads/b4x-eval-expressions-evaluator.54629/post-343073
M Mahares Expert Licensed User Longtime User Oct 16, 2020 #3 Pedro Caldeira said: it can be any other calculus, like "(234/403)-20*50" but they are string can I somehow convert them to numbers to perform the operations ? Click to expand... You can use Smart String Literals. Here is an example: Code: Copy Dim s As Double = $"${NumberFormat((234/403)-20*50, 1,4)}"$ Log(s) 'displays: -999.4194 Upvote 0
Pedro Caldeira said: it can be any other calculus, like "(234/403)-20*50" but they are string can I somehow convert them to numbers to perform the operations ? Click to expand... You can use Smart String Literals. Here is an example: Code: Copy Dim s As Double = $"${NumberFormat((234/403)-20*50, 1,4)}"$ Log(s) 'displays: -999.4194
stevel05 Expert Licensed User Longtime User Oct 16, 2020 #4 Mahares said: You can use Smart String Literals Click to expand... The number passed needs to be a valid number, it won't work if you pass a string. Upvote 0
Mahares said: You can use Smart String Literals Click to expand... The number passed needs to be a valid number, it won't work if you pass a string.
Pedro Caldeira Active Member Licensed User Longtime User Oct 16, 2020 #5 @stevel05 is right about the smart string, but the B4XClass works fine. Thanks guys Upvote 0
M Mahares Expert Licensed User Longtime User Oct 16, 2020 #6 stevel05 said: The number passed needs to be a valid number, it won't work if you pass a string. Click to expand... Steve: Could you please give an example where it won't work. I am not sure I understand what you are saying. I was going by the examples that Pedro wrote Thanks Upvote 0
stevel05 said: The number passed needs to be a valid number, it won't work if you pass a string. Click to expand... Steve: Could you please give an example where it won't work. I am not sure I understand what you are saying. I was going by the examples that Pedro wrote Thanks
stevel05 Expert Licensed User Longtime User Oct 16, 2020 #7 It's the calculation that is the problem. Pedro want's to be able to perform a calculation that is stored in a string which presumably is read from elsewhere. i.e. B4X: Copy Dim CalcStr as String = "(234/403)-20*50" Dim s As Double = $"${NumberFormat(CalcStr, 1,4)}"$ Which will fail. Upvote 0
It's the calculation that is the problem. Pedro want's to be able to perform a calculation that is stored in a string which presumably is read from elsewhere. i.e. B4X: Copy Dim CalcStr as String = "(234/403)-20*50" Dim s As Double = $"${NumberFormat(CalcStr, 1,4)}"$ Which will fail.