Javascript 使用存储为字符串的数字

Javascript 使用存储为字符串的数字,javascript,json,coffeescript,websocket,Javascript,Json,Coffeescript,Websocket,我想这个问题在CoffeScript和JavaScript中很常见。在我的CoffeeScript脚本中,我通过websocket接收到一个类似606.0的数字。因此,它是一个字符串,从从主机到达的JSON中提取。现在我想使用这个数字,比如说,在上面添加一些东西,比如: # @x is the number presented as a string @xx = @x + 100 console.log("res=" + @xx) 我得到的是: res=606.0100 所以它被添加为一个字

我想这个问题在CoffeScript和JavaScript中很常见。在我的CoffeeScript脚本中,我通过websocket接收到一个类似
606.0
的数字。因此,它是一个字符串,从从主机到达的JSON中提取。现在我想使用这个数字,比如说,在上面添加一些东西,比如:

# @x is the number presented as a string
@xx = @x + 100
console.log("res=" + @xx)
我得到的是:

res=606.0100
所以它被添加为一个字符串!如果我稍微修改一下代码,“说”100是浮点数:

# @x is the number presented as a string
@xx = @x + 100.0
console.log("res=" + @xx)
结果仍然是一样的


我的问题是-如何向CoffeScript/JavaScript解释这是一个数字,而不是一个字符串?

要从字符串中转换数字,只需在前面加上一个
+

n = '100'
alert n + 1 # 1001
alert +n + 1 # 101