# Android QuestionUse formula in string to calculate

#### Pedro Caldeira

##### Active Member
Longtime User
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

Longtime User

#### Mahares

##### Expert
Longtime User
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 ?
You can use Smart String Literals. Here is an example:
B4X:
``````Dim s As Double = \$"\${NumberFormat((234/403)-20*50, 1,4)}"\$
Log(s)  'displays: -999.4194``````

#### stevel05

##### Expert
Longtime User
You can use Smart String Literals
The number passed needs to be a valid number, it won't work if you pass a string.

#### Pedro Caldeira

##### Active Member
Longtime User
@stevel05 is right about the smart string, but the B4XClass works fine.
Thanks guys

#### Mahares

##### Expert
Longtime User
The number passed needs to be a valid number, it won't work if you pass a string.
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
Longtime User
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:
``````Dim CalcStr as String = "(234/403)-20*50"
Dim s As Double = \$"\${NumberFormat(CalcStr, 1,4)}"\$``````

Which will fail.

Replies
2
Views
902
Android Question aPOI FORMULA
Replies
0
Views
599
Android Question Polygon calculation
Replies
5
Views
3K
Replies
4
Views
2K
Share My Creation Tape calculator
Replies
16
Views
11K