Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coffeescript: how do I convert a string to a number?

Tags:

coffeescript

I am building a JSON object that is sent in a POST request. This object has properties that need to be converted from string type to integer type before sending. How does one do that with coffeescript?

like image 833
nachonachoman Avatar asked May 23 '12 13:05

nachonachoman


People also ask

How do I convert a string to a number in C++?

One effective way to convert a string object into a numeral int is to use the stoi() function. This method is commonly used for newer versions of C++, with is being introduced with C++11. It takes as input a string value and returns as output the integer version of it.

How do I convert a string to a number in Matlab?

X = str2num( txt ) converts a character array or string scalar to a numeric matrix. The input can include spaces, commas, and semicolons to indicate separate elements. If str2num cannot parse the input as numeric values, then it returns an empty matrix.

How do I convert a string to a number in JavaScript?

How to convert a string to a number in JavaScript using the parseInt() function. Another way to convert a string into a number is to use the parseInt() function. This function takes in a string and an optional radix. A radix is a number between 2 and 36 which represents the base in a numeral system.


1 Answers

Use the javascript parseInt function.

number = parseInt( stringToParse, 10 ); 

Reference is here.

Remember, coffeescript is just javascript after it's compiled

like image 107
obmarg Avatar answered Sep 28 '22 00:09

obmarg