Reputation: 1046
In Jquery, how do you take a variable and set a second variable with a decimal in front of the value of the first variable.
For example I have a variable that is set from a form input values. I named this variable subTotal
. Now I want to take that variable and set another variable with a decimal in front of it so I can calculate a percentage by multiplying another input value.
So here is some of the code for example
var subTotal = self.calculateTotalFor(elems);
total += (quantity - 1) * NewVariable;
self.calculateTotalFor(elems);
comes from the input on the formNewVariable
would be Subtotal with a decimal in front. Upvotes: 0
Views: 587
Reputation: 6178
Try this
var NewVariable = parseFloat("." + Subtotal);
This will take "."
and your Subtotal
value and perform a string
append
parseFloat
will convert the string to a floating point number
Upvotes: 0
Reputation: 792
Try :
var subTotal = self.calculateTotalFor(elems), total = 0;
total += (quantity - 1) * NewVariable;
or
total += parseFloat((quantity - 1) * NewVariable);
Upvotes: 1