· Feb 15

How can I transform a String, which is a numerical value, to an Integer?

Hello everyone!
I need to transform a String, which is a numerical value, to an Integer.
The value gets returned in my Rest service as "testingID": "1234567", but I need it to be "testingID": 1234567

Thanks beforehand! Appreciate all the help I can get! :)

Discussion (5)2
Log in or sign up to continue

Some additional picky details:

The unary + operator is a numeric operator so it converts its operand to a number.  If a string operand starts with a fractional number then unary + produces a fractional number (in its canonical numeric form) and it throws away any unneeded characters.  If you want your numeric result to be an integer then you need to throw away the fractional digits by doing an integer-division by 1.  Since the integer-division operator, \, is a numeric operator it always converts its operands to numbers so you no longer need the unary + to do the conversion of a string to numeric representation.  E.g.s:

USER>w "0012.543000abc"   
USER>w +"0012.543000abc"
USER>w +"0012.543000abc"\1
USER>w "0012.543000abc"\1