JQuery繁殖并添加 [英] JQuery multiply and add
问题描述
假设我有一些我希望成倍增加的数字。
Let's say I have some numbers that I want to multiply and add.
var a = 5;
var b = 10;
var c = 2;
var d = 3;
我想将b和c相加然后乘以a,然后加上d。容易吗?
I want to sum b and c then multiply that by a, then add d. Easy right?
如果是正常的等式,公式看起来像:(a *(b + c)+ d)
If if were a normal equation the formula would look like: (a * (b + c) + d)
但是我如何在JQuery中做到这一点?
But how do I do that in JQuery?
(注意:JQuery的原因是我将从字段和div中获取这些数字......并在其他地方放置总数等)。
(Note: the reason for JQuery is that I'll be getting these numbers from fields and divs... and placing a total elsewhere, etc.)
推荐答案
默认情况下,脚本语言不知道类型为 int
或浮
。所以你可以通过将1乘以你期望的数字来解决这个问题。
By default script language does not know type as int
or float
. So you can fix that by multiplying 1 to the value you expect to be a number.
var a = 5;
var b = 10;
var c = 2;
var d = 3;
var total = a*1 * (b*1 + c*1) + d*1;
这篇关于JQuery繁殖并添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!