Originally Posted by robertbaer
No; i had extracted one character from a string, and needed to change the type to integer; i did not need Einstein (math floor).
If you want to keep it simple:
var num = Number(title.charAt(16));
That will return an integer every time.
Or you can use felgall's abbreviated syntax (though I personally prefer the former for readability reasons):
var num = +title.charAt(16);
If you insist on using substrings, you might want to use the standardized version:
var num = Number(title.substring(16, 17));
Though a less brittle way to get the number is to use regular expressions. Then you can change the file names and directory structure and your script will still work:
// Returns number immediately preceding ".png".
var num = Number(title.match(/(\d+)\.png/));
// Reconstitute the previous title with the new number.
return title.replace(/\d+(\.png)/, String(num) + "$1");