Is there a straightforward way to parse a string to either integer or float if I don't know if the variable is integer-number-like or decimal-number-like?
a = '2'; // => parse to integer
b = '2.1'; // => parse to float
c = '2.0'; // => parse to float
d = 'text'; // => don't parse
EDIT: It seems my question lacked the necessary context: I want to do some calculations without losing the original format (Original format thereby means integer vs. float. I don't care about the original number of decimal places):
Example:
String containing the formatted number ('2')
=> parse to number (2.0)
=> do some calculations (2.0 + 1 = 3.0)
=> restore "original format" ('3' and not '3.0')
If the input was 2.0 instead, the wanted result would be '3.0' (not '3').