Michael Falciglia
Michael Falciglia

Reputation: 1046

Jquery - set a variable with a decimal in front

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;

Upvotes: 0

Views: 587

Answers (2)

jasonscript
jasonscript

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

Shyam
Shyam

Reputation: 792

Try :

var subTotal = self.calculateTotalFor(elems), total = 0;
total += (quantity - 1) * NewVariable;

or

total += parseFloat((quantity - 1) * NewVariable);

Upvotes: 1

Related Questions