JavaScript总和值 [英] Javascript Sum Values
本文介绍了JavaScript总和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要对javascript中的几个值求和.我已经尝试过使用以下代码
I need to sum several values in javascript. I've tried by using following code
var a = 2;
var b = 5;
c = a+b;
但是,除了计算a和b的值外,输出(c)仅合并了这两个值.所以给出的输出是:
But, instead of calculating the values of a and b, the output (c) only combine those two values. So the output given is :
c = 25
我相信你们可以在这方面帮助我.谢谢.问候安达.
I believe you guys can help me easily about this. Thx before. Regard Andha.
推荐答案
请确保值是数字,否则它们将连续而不是求和.
Make sure the values are numbers, otherwise they will concat instead of suming.
a = parseInt(a, 10); // a is now int
这篇关于JavaScript总和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文