Javascript is treating variables as Strings, why?

I have the variable y, which is a subtotal. Its value is different depending on what happens with the html, but throughout the script I declared it like this: var y = 21.78; etc. Why is it that on my last equation where I add up the total, it treats them as strings when I want to add the values? var tax = (0.055*y).toFixed(2); var totalprice = y+tax; /* totalprice holds "21.781.20" instead of 22.98 */
@Radu no, just a series of if else statements. y is always equal to a number like that, no other variables are involved in declaring it.

以上就是Javascript is treating variables as Strings, why?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准