function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

String expression is giving me the calculated value.

Hi All,

My code is returning a expression in string format. I need the calculated value in integer /double format.

String str = '25*5';
Integer result=Integer.valueOf(str);

Throwing error as Ivalid type exception.

Please help me on this .
Jason HuggerJason Hugger
First I would say I would try to not send it as a string. If this is not possible is it always multiplication or will the equation change? 
String str = '25*5';
string[] parts = str.split('\\*');
Integer val = integer.valueOf(parts[0]) * integer.valueOf(parts[1]);

system.debug('Value: ' + val);