Convert string to either integer or float in javascript
问题 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