Coffeescript: how do I convert a string to a number?
Use the javascript parseInt
function.
number = parseInt( stringToParse, 10 );
Reference is here.
Remember, coffeescript is just javascript after it's compiled
You can use the less obvious, more magical, less keyboard-intensive operator +:
+"158"
Javascript's parseInt function will achieve this. Remember to set the radix parameter to prevent confusion and ensure predictable behaviour. (E.g. in Coffeescript)
myNewInt = parseInt("176.67", 10)
There's a few good examples in the MDN resources: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt