Reputation: 35537
I need to perform a math calculation in JavaScript that I am unsure how to do so.
The formula is as follows:
result = (scale * weighting) / 2
where the result I will need to two decimal places.
Example formula that I need to do in JavaScript might be:
result = ((3 * 2) + (2 * 1.5)) / 2
I am also unsure if I have to also convert this to int.
Upvotes: 0
Views: 3050
Reputation: 41
In JavaScript everything number is a floating point number. No explicit type conversion needed.
ref : http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html ( search for "The Number Data Type" )
Upvotes: 0
Reputation: 35793
Not entirely sure what you want, but this might help:
result = Math.round(((scale * weighting) / 2) * 100) / 100;
Upvotes: 0